From 92f1e4866c3bca8b77dd338e8290ba6f41e0658f Mon Sep 17 00:00:00 2001
From: Andrews Sobral <andrewssobral@gmail.com>
Date: Sun, 19 Mar 2017 04:32:33 +0100
Subject: [PATCH] Some fixes for the MATLAB wrapper

---
 wrapper_matlab/.gitignore                   |   4 +
 wrapper_matlab/README.txt                   |  28 ++
 wrapper_matlab/README_visionopencv.txt      |  81 ++++++
 wrapper_matlab/opencvinterface.mlpkginstall | 283 ++++++++++++++++++++
 wrapper_matlab/run_demo.m                   |  14 +-
 5 files changed, 408 insertions(+), 2 deletions(-)
 create mode 100644 wrapper_matlab/README.txt
 create mode 100644 wrapper_matlab/README_visionopencv.txt
 create mode 100644 wrapper_matlab/opencvinterface.mlpkginstall

diff --git a/wrapper_matlab/.gitignore b/wrapper_matlab/.gitignore
index 1c363bf..fb0ba78 100644
--- a/wrapper_matlab/.gitignore
+++ b/wrapper_matlab/.gitignore
@@ -1 +1,5 @@
 *.mex*
+*.asv
+*.exe
+*.dll
+*.lib
diff --git a/wrapper_matlab/README.txt b/wrapper_matlab/README.txt
new file mode 100644
index 0000000..1c79cf5
--- /dev/null
+++ b/wrapper_matlab/README.txt
@@ -0,0 +1,28 @@
+---------------------------------------
+- BUILDING BGSLIBRARY MATLAB WRAPPER -
+---------------------------------------
+Tested on MATLAB R2015b and R2016b
+
+* Dependencies:
+* * Computer Vision System Toolbox OpenCV Interface
+https://fr.mathworks.com/matlabcentral/fileexchange/47953-computer-vision-system-toolbox-opencv-interface
+* * * It provides wrapper files for OpenCV 2.4.9
+
+* Compatible compilers:
+    Windows 32 bit: MS Visual Studio 2012
+    Windows 64 bit: MS Visual Studio 2012
+    Linux 64 bit: gcc-4.7.2 (g++)
+    Mac 64 bit: Xcode 6.2.0 (Clang++)
+		
+* * Note: It works successfully with MS Visual Studio 2013
+		
+* First install [Computer Vision System Toolbox OpenCV Interface]
+* * Go to: bgslibrary/wrapper_matlab
+* * Double-click on [opencvinterface.mlpkginstall] inside your MATLAB.
+-- wait installation, it takes a few minutes ---
+
+* Run: compile.m
+
+* Run demo: demo.m
+
+* See [run_demo.m] for more info
diff --git a/wrapper_matlab/README_visionopencv.txt b/wrapper_matlab/README_visionopencv.txt
new file mode 100644
index 0000000..a802f6f
--- /dev/null
+++ b/wrapper_matlab/README_visionopencv.txt
@@ -0,0 +1,81 @@
+CONTENTS OF THIS FILE
+---------------------
+* Introduction
+* Requirements
+* Installation
+* Contents
+* Utility functions
+* How to compile OpenCV mex function
+* Example
+
+
+INTRODUCTION
+------------
+"Computer Vision System Toolbox OpenCV Interface" is used to create mex files 
+that link against OpenCV. The support package also contains graphics 
+processing unit (GPU) support. 
+
+REQUIREMENTS
+------------
+This package requires the following:
+* Computer Vision System Toolbox® Version R2016a installation
+* A compatible C++ compiler
+
+The mex function uses pre-built OpenCV libraries which are shipped with the 
+Computer Vision System Toolbox. Your compiler must be compatible with the 
+pre-built OpenCV libraries. The following is a list of compatible compilers:
+    Windows 32 bit: MS Visual Studio 2012
+    Windows 64 bit: MS Visual Studio 2012
+    Linux 64 bit: gcc-4.7.2 (g++)
+    Mac 64 bit: Xcode 6.2.0 (Clang++)
+
+INSTALLATION
+------------
+Use the support package installer which can be invoked using the  
+visionSupportPackages function.
+After the support package is installed, the location of the package can be 
+found by executing the following MATLAB command:
+>> fileparts(which('mexOpenCV.m'))
+
+CONTENTS
+--------
+In addition to the files and folders required by the support package installer, 
+the package contains the following folder:
+
+example: Six subfolders containing examples. Each subfolder contains source 
+	 file that calls the OpenCV function and the test script to test the 
+	 generated mex file.
+
+UTILITY FUNCTIONS
+-----------------
+The support package uses a set of utility functions to marshall data 
+between OpenCV and MATLAB. It supports only CPP-linkage. GPU support is 
+only available on glnxa64 and win64 platforms. The utility functions support 
+CUDA-enabled NVIDIA GPU with compute capability 2.0 or higher. 
+
+General purpose utility functions are available at:
+  (matlabroot)/extern/include/opencvmex.hpp
+Utility functions for GPU support are available at:
+  (matlabroot)/extern/include/opencvgpumex.hpp
+
+HOW TO COMPILE OPENCV MEX FUNCTION
+----------------------------------
+Follow these steps:
+1. Change your current working folder to the folder where the source file is located. 
+2. Call the mexOpenCV function with the source file. 
+>> mexOpenCV yourfile.cpp
+
+To get more information, type the following at the MATLAB command prompt:
+>> help mexOpenCV
+
+EXAMPLES
+--------
+There are three examples included in the package: 
+* Template Matching (includes regular and GPU versions)
+* Image registration using ORB detector and descriptor (includes regular, 
+  GPU and code-generation versions)
+* Foreground Detection
+
+To run them, follow the steps in the README.txt file located in the corresponding 
+sub-folders of the examples folder.
+
diff --git a/wrapper_matlab/opencvinterface.mlpkginstall b/wrapper_matlab/opencvinterface.mlpkginstall
new file mode 100644
index 0000000..2d7683d
--- /dev/null
+++ b/wrapper_matlab/opencvinterface.mlpkginstall
@@ -0,0 +1,283 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+This file should be opened using MATLAB (http://www.mathworks.com).
+To open it with a specific instance of MATLAB, 
+ a) Open MATLAB,
+ b) Browse to this file using the Current Folder Browser, and
+ c) Double-click on this file
+
+Copyright 2014 The MathWorks, Inc.
+-->
+<MWSignpost>
+
+  <PackageInfo version="1.0">
+    <SignpostData>
+       <Repository>MathWorks</Repository>
+       <Name>OpenCV Interface</Name>
+       <BaseProduct>Computer Vision System Toolbox</BaseProduct>
+       <FullName>Computer Vision System Toolbox OpenCV Interface</FullName>
+       <BaseCode>CVST_OPENCV_INTERFACE</BaseCode>
+    </SignpostData>
+    <Signature>C0753A7DD7BC6A2500F8268502F7D019</Signature>
+  </PackageInfo>
+
+</MWSignpost>
+
+<!-- License for this .mlpkginstall file
+
+MATHWORKS LIMITED LICENSE
+
+IMPORTANT NOTICE
+
+READ THE TERMS AND CONDITIONS OF THIS MATHWORKS LIMITED LICENSE AGREEMENT
+(THE "AGREEMENT") CAREFULLY BEFORE ACCESSING THESE MATERIALS (AS DEFINED
+BELOW).
+
+THIS AGREEMENT REPRESENTS THE ENTIRE AGREEMENT BETWEEN YOU (THE "LICENSEE")
+AND THE MATHWORKS, INC. ("MATHWORKS") CONCERNING THE SOFTWARE AND
+DOCUMENTATION MADE AVAILABLE FOR ACCESS HEREUNDER (COLLECTIVELY, THE
+"MATERIALS").
+
+BY ACCESSING THESE MATERIALS, YOU ACCEPT THE TERMS OF THIS AGREEMENT.
+
+1. DEFINITIONS.
+
+  1.1. "Licensee" means you, whether an individual or an entity, to whom
+  MathWorks grants the License, and who is responsible for complying with the
+  contractual obligations of the License, and ensuring that anyone permitted
+  access to the Materials also complies with such obligations.
+
+  1.2. "Documentation" means the user guides, if any, accompanying delivery
+  of the Materials, as may be updated from time to time, as well as any
+  reports or other feedback that MathWorks may, in its sole discretion,
+  provide to Licensee.  Documentation may be delivered in printed and/or
+  online forms, and in one or more languages.
+
+  1.3. "Licensor" means any person who, or entity which, grants a license
+  to MathWorks to redistribute that person's or entity's intellectual
+  property.
+
+  1.4. "Materials" means the computer software delivered and licensed
+  hereunder, including Documentation, enhancements and error corrections.
+
+  1.5. "Third Party" means any person or legal entity that is not MathWorks
+  or the Licensee.
+
+2. LICENSE GRANT.  MathWorks hereby grants to Licensee, subject to the
+terms of this Agreement, a nonexclusive, nontransferable, revocable license
+(the "License") to use the Materials internally or for the purpose of
+providing to MathWorks engineering feedback on the Materials, as the context
+ may require.  In all cases, the Materials are licensed to you solely for
+ use in conjunction with MathWorks products and services.
+
+3. LICENSE RESTRICTIONS.  The License is subject to the express
+restrictions set forth below. Licensee shall not, and shall not permit any
+Third Party to:
+
+  3.1. modify, or create any derivative work of, any part of the licensed
+  Materials
+
+  3.2. adapt, translate, copy, or convert all or any part of the Materials
+  in order to create software or other materials, a principal purpose of
+  which is (a) to perform the same or similar functions as the Materials or
+  any other technology or materials licensed by MathWorks, or (b) to replace
+  any component of the Materials or any other technology or materials
+  licensed by MathWorks;
+
+  3.3. rent, lease, or loan the Materials; use the Materials for supporting
+   Third Parties' use of the Materials, time share the Materials, or provide
+   service bureau use;
+
+  3.4. disassemble, decompile, reverse engineer the Materials or otherwise
+  attempt to gain access to its method of operation or source code (other
+  than files provided for convenience in source code form by MathWorks);
+
+  3.5. sell, license, sublicense, publish, display, distribute, disseminate,
+  assign, or otherwise transfer (whether by sale, exchange, lease, gift, or
+  otherwise) to a Third Party the Materials, any copy or portion thereof, or
+  any License or other rights thereto, in whole or in part, without MathWorks'
+  prior written consent;
+
+  3.6. alter, remove, or obscure any copyright, trade secret, patent,
+  trademark, logo, proprietary and/or other legal notices on or in copies of
+  the Materials;
+
+  3.7. use MathWorks' name, trade names, logos, or other trademarks of
+  MathWorks or any of its affiliates or Licensors in any advertising,
+  promotional literature or any other material, whether in written,
+  electronic, or other form, distributed to any Third Party, except in the
+  form provided by MathWorks, and then solely for purposes of identifying
+  MathWorks' Materials;
+
+  3.8. provide access (directly or indirectly) to the Materials via a web or
+  network application other than the licensee's internal network;
+
+  3.9. copy, make available for copy, or otherwise reproduce the Materials,
+  in whole or in part, except either (a) as may be required for their
+  installation into computer memory for the purpose of executing the
+  Materials in accordance with this Agreement; or (b) to make a reasonable
+  number of copies solely for back-up purposes provided that any such
+  permitted copies shall reproduce all copyright, trade secret, patent, logo,
+  proprietary and/or other legal notices contained in the original copy
+  obtained from MathWorks; and/or
+
+  3.10. republish the Documentation.
+
+4. RETENTION OF RIGHT, TITLE AND INTEREST BY MATHWORKS AND ITS LICENSORS;
+CONFIDENTIALITY.  The Materials shall at all times remain the property of
+MathWorks and/or its Licensors and Licensee shall have no right, title, or
+interest therein, except as expressly set forth in this Agreement.  The
+Materials are a commercially valuable product of MathWorks, the design and
+development of which reflect the efforts of skilled development experts and
+the investment of considerable time and expense. MathWorks claims and
+reserves all rights and benefits afforded under all relevant laws and
+regulations. Licensee shall take appropriate action by instruction,
+agreement, or otherwise with any persons permitted access to the Materials,
+so as to enable Licensee to satisfy its obligations under the terms of this
+Agreement.  The Materials are proprietary information of MathWorks, and are
+protected by copyright law, trade secret law and other applicable law.
+Although MathWorks may consider a commercial release of the Materials, it
+is under no obligation to do so and MathWorks reserves the right to alter
+features, licensing terms, or other characteristics of any such commercial
+release.
+
+5. LICENSES FOR THIRD PARTY SOFTWARE.  MathWorks has been granted licenses
+to distribute certain Third Party software.  Certain MathWorks Materials
+require the use of Third Party software products that may require a
+separate license from such Third Parties to use those Third Party products.
+Licensee agrees and acknowledges that, to the extent that the Materials
+contain any Third Party software: (i) such Third Party software is provided
+on an "as-is", pass-through basis, and as such is provided to Licensee
+without warranty, indemnification, support or other representation by
+MathWorks; and (ii) MathWorks bears no liability with respect to such Third
+Party software.
+
+6. TERM AND TERMINATION.  This Agreement shall continue until termination
+by MathWorks or Licensee as provided below.  Either party may terminate this
+Agreement at any time, for any reason, upon written notice to the other
+party.  Upon termination, Licensee shall promptly return all but archival
+copies of the Materials in Licensee's possession or control, or promptly
+provide written certification of their destruction.
+
+7. EXPORT CONTROL.  The Materials may be subject to U.S. export control
+laws or other (U.S. and non-U.S.) governmental export and import laws and
+regulations.  Notwithstanding any other term of this Agreement or Third
+Party agreement, Licensee's rights under this Agreement may not be
+exercised by Licensee or any Third Party in violation of such laws and
+regulations, nor may this Agreement be transferred to any party where
+doing so would result in such a violation.  The terms of any limitation on
+the use, transfer or re-export of the Materials imposed by MathWorks in any
+Destination Control Statement or other document for the purpose of export
+control shall prevail over any term in this Agreement.  It shall be
+Licensee's responsibility to comply with the latest United States or other
+governmental export and import regulations.
+
+8. FEDERAL ACQUISITION.  This provision applies to all acquisitions of the
+Materials and Documentation by, for, or through the federal government of
+the United States.  By accepting delivery of the Materials or
+Documentation, the government hereby agrees that this software or
+documentation qualifies as commercial computer software or commercial
+computer software documentation as such terms are used or defined in FAR
+12.212, DFARS Part 227.72, and DFARS 252.227-7014.  Accordingly, the terms
+and conditions of this Agreement and only those rights specified in this
+Agreement, shall pertain to and govern the use, modification, reproduction,
+release, performance, display, and disclosure of the Materials and
+Documentation by the federal government (or other entity acquiring for or
+through the federal government) and shall supersede any conflicting
+contractual terms or conditions.  If this License fails to meet the
+government's needs or is inconsistent in any respect with federal
+procurement law, the government agrees to return the Materials and
+Documentation, unused, to MathWorks.
+
+9. FOR EUROPEAN UNION LICENSEES ONLY.  Any contractual provisions of this
+Agreement contrary to laws implemented under Article 6 of Appendix V of the
+European Union Software Directive or to the exceptions provided for in
+Article 5(2) and (3) of such Appendix shall be null and void solely to the
+extent decompiling, disassembling, or otherwise reverse-engineering of the
+Materials is necessary to enable the Licensee to create an independent
+program that is interoperable with the Materials or any other permitted
+objectives specified by such laws implemented under such directive
+(collectively, the "Permitted Objectives"), provided that any such
+information gained is used solely for such Permitted Objectives.
+
+10. ASSIGNMENT.  Licensee may not assign or otherwise transfer this
+Agreement and its rights and obligations hereunder, in whole or in part, by
+operation of law or otherwise, without the written consent of MathWorks.
+In the case of any permitted assignment or transfer of or under this
+Agreement, this Agreement or the relevant provisions shall be binding upon,
+and inure to the benefit of, the successors, executors, heirs,
+representatives, administrators and assigns of the parties hereto.
+MathWorks may charge Licensee an administrative fee for any permitted
+assignment.
+
+11. LIMITATION OF LIABILITY.  The Materials should not be relied on as the
+sole basis to solve a problem or implement a design whose incorrect solution
+or implementation could result in injury to person or property.  If the
+Materials are employed in such a manner, it is at the Licensee's own risk
+and MathWorks and its Licensors explicitly disclaim all liability for such
+misuse to the extent allowed by law.  MathWorks' and its Licensors'
+liability for death or personal injury resulting from negligence or for any
+other matter in relation to which liability by law cannot be excluded or
+limited shall not be excluded or limited.  Except as aforesaid, (a) any
+other liability of MathWorks and its Licensors (whether in relation to
+breach of contract, negligence or otherwise) shall not in total exceed one
+hundred dollars ($100.00); and (b) MathWorks and its Licensors shall have
+no liability for any indirect or consequential loss (whether foreseeable or
+otherwise and including loss of profits, loss of business, loss of
+opportunity, and loss of use of any computer hardware or software).  Some
+states do not allow the exclusion or limitation of incidental or
+consequential damages, so the above exclusion or limitation may not apply
+to Licensee.
+
+12. DISCLAIMER OF WARRANTIES.  The Materials are delivered "as is" and
+MathWorks makes and the Licensee receives no additional express or implied
+warranties.  MathWorks and its Licensors hereby expressly disclaim any and
+all other conditions, warranties, or other terms of any kind or nature
+concerning the Materials (including, without limitation, any with regard to
+infringement, merchantability, quality, accuracy, or fitness for a
+particular purpose or Licensee's purpose).  MathWorks also expressly
+disclaims any warranties that may be implied from usage of trade, course of
+dealing, or course of performance.  The Materials are provided with all
+faults, and the entire risk of satisfactory quality, performance, accuracy,
+and effort is with Licensee.  MathWorks does not warrant that the Materials
+will operate without interruption or be error free.  Some states and
+countries do not allow limitations on how long an implied warranty lasts,
+so the above limitation may not apply to Licensee.  Licensee may also have
+other rights which vary from state to state and country to country.
+Licensee accepts responsibility for its use of the Materials and the
+results obtained therefrom.
+
+13. GOVERNING LAW; JURISDICTION.  This Agreement shall be interpreted,
+enforced and construed and the rights of the parties hereunder governed in
+all respects by the laws of the Commonwealth of Massachusetts, United
+States of America, without regard to its conflicts of law provisions, and
+both parties consent to the jurisdiction of the federal and state courts
+located in said Commonwealth and consent to the service of process,
+pleadings and notices in connection with any and all actions initiated in
+such courts.  The parties agree that a final judgment in any such action or
+proceeding shall be conclusive and binding and may be enforced in any other
+jurisdiction.  To the extent any governing law, treaty, or regulation is in
+conflict with this Agreement, the conflicting terms of this Agreement shall
+be superseded only to the extent necessary by such law, treaty, or
+regulation.  If any provision of this Agreement shall be otherwise
+unlawful, void, or otherwise unenforceable, that provision shall be
+enforced to the maximum extent permissible.  In either case, the remainder
+of this Agreement shall not be affected.  The parties agree that the U.N.
+Convention on Contracts for the International Sale of Goods shall not apply
+to this Agreement.  The parties further agree that the Uniform Computer
+Information Transactions Act, or any version thereof, adopted by any state,
+in any form ("UCITA"), shall not apply to this Agreement.  To the extent
+that UCITA is applicable, the parties agree to opt out of the
+applicability of UCITA pursuant to the Opt-Out provision(s) contained
+therein.
+
+14. HEADINGS.  The inclusion of headings is for convenience of reference
+only and shall not affect the construction or interpretation of this
+Agreement.
+
+15. ENTIRE AGREEMENT.  This Agreement, together with any additional
+license_addendum.txt file included with the Materials, contains the entire
+understanding of the parties with regard to the Materials, and may not be
+modified or amended except by written instrument, executed by authorized
+representatives of MathWorks and Licensee.
+-->
diff --git a/wrapper_matlab/run_demo.m b/wrapper_matlab/run_demo.m
index e27174d..d7afed4 100644
--- a/wrapper_matlab/run_demo.m
+++ b/wrapper_matlab/run_demo.m
@@ -1,11 +1,21 @@
+%% Installation instructions
+% First install the 'Computer Vision System Toolbox OpenCV Interface'
+% by double-clicking on 'opencvinterface.mlpkginstall'
+%
+% More info:
+% https://fr.mathworks.com/help/vision/ug/opencv-interface.html
+% https://fr.mathworks.com/help/vision/opencv-interface-support-package.html
+% https://fr.mathworks.com/matlabcentral/fileexchange/47953-computer-vision-system-toolbox-opencv-interface
+
 %% Compile the BGSLibrary wrapper
-compile;
+% Run 'compile' for your first usage.
+% compile;
 
 %% Run demo
 demo;
 
 %% Run a specific algorithm
-demo('FrameDifference')
+% demo('FrameDifference')
 % demo('StaticFrameDifference')
 % demo('WeightedMovingMean')
 % demo('WeightedMovingVariance')
-- 
GitLab