mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 03:30:34 +08:00
Starting writing Matlab testing framework
This commit is contained in:
parent
31415e344f
commit
bbece095fb
@ -7,6 +7,7 @@
|
||||
# MATLAB_FOUND: true/false
|
||||
# MATLAB_ROOT_DIR: Root of Matlab installation
|
||||
# MATLAB_MEX_SCRIPT: The mex script used to compile mex files
|
||||
# MATLAB_BIN: The actual Matlab executable
|
||||
# MATLAB_INCLUDE_DIR: Path to "mex.h"
|
||||
# MATLAB_LIBRARY_DIR: Path to mex and matrix libraries
|
||||
# MATLAB_LIBS: The Matlab libs, usually mx, mex, mat
|
||||
@ -119,8 +120,12 @@ function(locate_matlab_components MATLAB_ROOT_DIR)
|
||||
# get the mex shell script
|
||||
find_file(MATLAB_MEX_SCRIPT_ NAMES mex mex.bat PATHS ${MATLAB_ROOT_DIR}/bin NO_DEFAULT_PATH)
|
||||
|
||||
# get the Matlab executable
|
||||
find_file(MATLAB_BIN_ NAMES matlab matlab.exe PATHS ${MATLAB_ROOT_DIR}/bin NO_DEFAULT_PATH)
|
||||
|
||||
# export into parent scope
|
||||
if (MATLAB_MEX_SCRIPT_ AND MATLAB_LIBS_ AND MATLAB_INCLUDE_DIR_)
|
||||
set(MATLAB_BIN ${MATLAB_BIN_} PARENT_SCOPE)
|
||||
set(MATLAB_MEX_SCRIPT ${MATLAB_MEX_SCRIPT_} PARENT_SCOPE)
|
||||
set(MATLAB_INCLUDE_DIR ${MATLAB_INCLUDE_DIR_} PARENT_SCOPE)
|
||||
set(MATLAB_LIBS ${MATLAB_LIBS_} PARENT_SCOPE)
|
||||
@ -151,7 +156,7 @@ if (NOT MATLAB_FOUND)
|
||||
endif()
|
||||
find_package_handle_standard_args(Matlab DEFAULT_MSG MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIR
|
||||
MATLAB_ROOT_DIR MATLAB_LIBS MATLAB_LIBRARY_DIR
|
||||
MATLAB_MEXEXT MATLAB_ARCH)
|
||||
MATLAB_MEXEXT MATLAB_ARCH MATLAB_BIN)
|
||||
|
||||
# if Matlab was not found, unset the local variables
|
||||
if (NOT MATLAB_FOUND)
|
||||
|
@ -46,14 +46,16 @@ ocv_add_module(matlab BINDINGS opencv_core opencv_imgproc
|
||||
opencv_highgui opencv_ml opencv_calib3d opencv_photo
|
||||
opencv_nonfree opencv_calib)
|
||||
|
||||
set(HDR_PARSER_PATH ${OPENCV_MODULE_opencv_python_LOCATION}/src2)
|
||||
|
||||
# get the include path of the Bridge
|
||||
prepend("-I" MEX_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
if (BUILD_TESTS)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Configure time components
|
||||
# ----------------------------------------------------------------------------
|
||||
set(HDR_PARSER_PATH ${OPENCV_MODULE_opencv_python_LOCATION}/src2)
|
||||
prepend("-I" MEX_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
message("-- Trying to generate Matlab code")
|
||||
execute_process(
|
||||
COMMAND ${PYTHON_EXECUTABLE}
|
||||
@ -124,3 +126,7 @@ foreach(SOURCE_FILE ${SOURCE_FILES})
|
||||
DEPENDS opencv_matlab_sources
|
||||
)
|
||||
endforeach()
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Install time components
|
||||
# ----------------------------------------------------------------------------
|
||||
|
@ -1,8 +1,5 @@
|
||||
# glob the source files
|
||||
file(GLOB SOURCE_FILES *.cpp)
|
||||
|
||||
# compile each source
|
||||
foreach(SOURCE_FILE_ ${SOURCE_FILES})
|
||||
get_filename_component(SOURCE_FILE_NAME_ ${SOURCE_FILE_} NAME_WE)
|
||||
add_custom_target(${SOURCE_FILE_NAME_} ALL ${MATLAB_MEX_SCRIPT} ${SOURCE_FILE_})
|
||||
endforeach()
|
||||
# run the matlab test suite
|
||||
add_test(opencv_matlab_test
|
||||
COMMAND ${MATLAB_BIN} "-nodisplay" "-r" "testsuite.m"
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
17
modules/matlab/test/OpenCVTest.m
Normal file
17
modules/matlab/test/OpenCVTest.m
Normal file
@ -0,0 +1,17 @@
|
||||
% Matlab binding test cases
|
||||
% Uses Matlab's builtin testing framework
|
||||
classdef OpenCVTest < matlab.unittest.TestCase
|
||||
|
||||
methods(Test)
|
||||
|
||||
% check if the autogenerated functions can be found
|
||||
function randExists(testcase)
|
||||
try
|
||||
cv.rand();
|
||||
catch
|
||||
testcase.verifyFail();
|
||||
end
|
||||
testcase.verifyTrue(true);
|
||||
end
|
||||
end
|
||||
end
|
33
modules/matlab/test/cv_exception.cpp
Normal file
33
modules/matlab/test/cv_exception.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* file: exception.cpp
|
||||
* author: Hilton Bristow
|
||||
* date: Wed, 19 Jun 2013 11:15:15
|
||||
*
|
||||
* See LICENCE for full modification and redistribution details.
|
||||
* Copyright 2013 The OpenCV Foundation
|
||||
*/
|
||||
#include <exception>
|
||||
#include <opencv2/core.hpp>
|
||||
#include "mex.h"
|
||||
|
||||
/*
|
||||
* exception
|
||||
* Gateway routine
|
||||
* nlhs - number of return arguments
|
||||
* plhs - pointers to return arguments
|
||||
* nrhs - number of input arguments
|
||||
* prhs - pointers to input arguments
|
||||
*/
|
||||
void mexFunction(int nlhs, mxArray* plhs[],
|
||||
int nrhs, const mxArray* prhs[]) {
|
||||
|
||||
// call the opencv function
|
||||
// [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn);
|
||||
try {
|
||||
throw cv::exception;
|
||||
} catch(cv::exception& e) {
|
||||
mexErrMsgTxt(e.what());
|
||||
} catch(...) {
|
||||
mexErrMsgTxt("Incorrect exception caught!");
|
||||
}
|
||||
}
|
29
modules/matlab/test/exception.cpp
Normal file
29
modules/matlab/test/exception.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* file: exception.cpp
|
||||
* author: Hilton Bristow
|
||||
* date: Wed, 19 Jun 2013 11:15:15
|
||||
*
|
||||
* See LICENCE for full modification and redistribution details.
|
||||
* Copyright 2013 The OpenCV Foundation
|
||||
*/
|
||||
#include "mex.h"
|
||||
|
||||
/*
|
||||
* exception
|
||||
* Gateway routine
|
||||
* nlhs - number of return arguments
|
||||
* plhs - pointers to return arguments
|
||||
* nrhs - number of input arguments
|
||||
* prhs - pointers to input arguments
|
||||
*/
|
||||
void mexFunction(int nlhs, mxArray* plhs[],
|
||||
int nrhs, const mxArray* prhs[]) {
|
||||
|
||||
// call the opencv function
|
||||
// [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn);
|
||||
try {
|
||||
throw 1;
|
||||
} catch(...) {
|
||||
mexErrMsgTxt("Uncaught exception occurred!");
|
||||
}
|
||||
}
|
32
modules/matlab/test/std_exception.cpp
Normal file
32
modules/matlab/test/std_exception.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* file: exception.cpp
|
||||
* author: Hilton Bristow
|
||||
* date: Wed, 19 Jun 2013 11:15:15
|
||||
*
|
||||
* See LICENCE for full modification and redistribution details.
|
||||
* Copyright 2013 The OpenCV Foundation
|
||||
*/
|
||||
#include <exception>
|
||||
#include "mex.h"
|
||||
|
||||
/*
|
||||
* exception
|
||||
* Gateway routine
|
||||
* nlhs - number of return arguments
|
||||
* plhs - pointers to return arguments
|
||||
* nrhs - number of input arguments
|
||||
* prhs - pointers to input arguments
|
||||
*/
|
||||
void mexFunction(int nlhs, mxArray* plhs[],
|
||||
int nrhs, const mxArray* prhs[]) {
|
||||
|
||||
// call the opencv function
|
||||
// [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn);
|
||||
try {
|
||||
throw std::exception();
|
||||
} catch(std::exception& e) {
|
||||
mexErrMsgTxt(e.what());
|
||||
} catch(...) {
|
||||
mexErrMsgTxt("Incorrect exception caught!");
|
||||
}
|
||||
}
|
5
modules/matlab/test/testsuite.m
Normal file
5
modules/matlab/test/testsuite.m
Normal file
@ -0,0 +1,5 @@
|
||||
%setup the tests
|
||||
opencv_tests = OpenCVTest();
|
||||
|
||||
%run the tests
|
||||
result = run(opencv_tests);
|
Loading…
Reference in New Issue
Block a user