/** Implementation of MxArray.
* @file MxArray.cpp
* @author Kota Yamaguchi
* @date 2012
*/
#include "MxArray.hpp"
namespace {
/// Field names for cv::Moments.
const char *cv_moments_fields[24] = {
"m00", "m10", "m01", "m20", "m11", "m02","m30", "m21", "m12", "m03",
"mu20", "mu11", "mu02", "mu30", "mu21", "mu12", "mu03",
"nu20", "nu11", "nu02", "nu30", "nu21", "nu12", "nu03"};
/// Field names for cv::RotatedRect.
const char *cv_rotated_rect_fields[3] = {"center", "size", "angle"};
/// Field names for cv::TermCriteria.
const char *cv_term_criteria_fields[3] = {"type", "maxCount", "epsilon"};
/// Field names for cv::KeyPoint.
const char *cv_keypoint_fields[6] = {"pt", "size", "angle", "response",
"octave", "class_id"};
/// Field names for cv::DMatch.
const char *cv_dmatch_fields[4] = {"queryIdx", "trainIdx", "imgIdx",
"distance"};
/** Translates data type definition used in MATLAB to that of OpenCV.
* @param classid data type of MATLAB's mxArray. e.g., \c mxDOUBLE_CLASS.
* @return OpenCV's data type. e.g., \c CV_8U.
*/
const ConstMap<mxClassID, int> DepthOf = ConstMap<mxClassID, int>
(mxDOUBLE_CLASS, CV_64F)
(mxSINGLE_CLASS, CV_32F)
(mxINT8_CLASS, CV_8S)
(mxUINT8_CLASS, CV_8U)
(mxINT16_CLASS, CV_16S)
(mxUINT16_CLASS, CV_16U)
(mxINT32_CLASS, CV_32S)
(mxUINT32_CLASS, CV_32S)
(mxLOGICAL_CLASS, CV_8U);
/** Translates data type definition used in OpenCV to that of MATLAB.
* @param depth data depth of OpenCV's Mat class. e.g., \c CV_32F.
* @return data type of MATLAB's mxArray. e.g., \c mxDOUBLE_CLASS.
*/
const ConstMap<int,mxClassID> ClassIDOf = ConstMap<int,mxClassID>
(CV_64F, mxDOUBLE_CLASS)
(CV_32F, mxSINGLE_CLASS)
(CV_8S, mxINT8_CLASS)
(CV_8U, mxUINT8_CLASS)
(CV_16S, mxINT16_CLASS)
(CV_16U, mxUINT16_CLASS)
(CV_32S, mxINT32_CLASS);
/** Comparison operator for sparse matrix elements.
* This functor sorts SparseMat nodes in column-major order.
* Only meant to be used on arrays with 2 dimensions.
*/
struct CompareSparseMatNode {
/// Comparison functor
bool operator () (const cv::SparseMat::Node* rhs,
const cv::SparseMat::Node* lhs) const
{
// sort by column, then by row
if (rhs->idx[1] < lhs->idx[1])
return true;
if (rhs->idx[1] == lhs->idx[1] && rhs->idx[0] < lhs->idx[0])
return true;
return false;
}
};
/// Inverse TermCriteria type map for option processing.
const ConstMap<int, std::string> InvTermCritType = ConstMap<int, std::string>
(cv::TermCriteria::COUNT, "Count")
(cv::TermCriteria::EPS, "EPS")
(cv::TermCriteria::COUNT+cv::TermCriteria::EPS, "Count+EPS");
/// TermCriteria type map for option processing.
const ConstMap<std::string, int> TermCritType = ConstMap<std::string, int>
("Count", cv::TermCriteria::COUNT)
("EPS", cv::TermCriteria::EPS)
("Count+EPS", cv::TermCriteria::COUNT+cv::TermCriteria::EPS);
} // anonymous namespace
int MexErrorHandler(int status, const char *func_name, const char *err_msg,
const char *file_name, int line, void * /*userdata*/)
{
mexErrMsgIdAndTxt("mexopencv:error",
"OpenCV Error:\n"
" Status : %s (%d)\n"
" Message : %s\n"
" Function: %s\n"
" File : <a href=\"matlab:opentoline('%s',%d)\">%s</a>\n"
" Line : %d\n",
cvErrorStr(status), status, err_msg,
(func_name ? func_name : "(unknown)"),
file_name, line, file_name, line);
return 0;
}
MxArray& MxArray::operator=(const MxArray& rhs)
{
if (this != &rhs)
this->p_ = rhs.p_;
return *this;
}
MxArray::MxArray(const int i)
: p_(mxCreateDoubleScalar(static_cast<double>(i)))
{
if (!p_)
mexErrMsgIdAndTxt("mexopencv:error", "Allocation error");
}
MxArray::MxArray(const double d)
: p_(mxCreateDoubleScalar(d))
{
if (!p_)
mexErrMsgIdAndTxt("mexopencv:error", "Allocation error");
}
MxArray::MxArray(const bool b)
: p_(mxCreateLogicalScalar(b))
{
if (!p_)
mexErrMsgIdAndTxt("mexopencv:error", "Allocation error");
}
MxArray::MxArray(const std::string& s)
: p_(mxCreateString(s.c_str()))
{
if (!p_)
mexErrMsgIdAndTxt("mexopencv:error", "Allocation error");
}
#if 0
// - works for multi-channel arrays, but doesnt work for ND-arrays because
// the order of dimensions is not right (row to column major order)
// (the std::swap below only gets it right for 2D arrays).
// - There's another bug regarding multi-channel arrays where mat.channels()
// is limited because of cv::transpose, which is only implemented for a number
// of cases, and asserts that mat.elementSize() <= 32
// (elementSize = sizeof(depth)*nchannels), so for mat.depth()==CV_8U we can
// go up to 32 channels, but for mat.depth()==CV_64F we can only go up to a
// maximum of 4 channels (8*4 == 32)
MxArray::MxArray(const cv::Mat& mat, mxClassID classid, bool transpose)
{
// handle special case of empty input Mat by creating an empty array
classid = (classid == mxUNKNOWN_CLASS) ? ClassIDOf[mat.depth()] : classid;
if (mat.empty()) {
p_ = mxCreateNumericMatrix(0, 0, classid, mxREAL);
if (!p_)
mexErrMsgIdAndTxt("mexopencv:error", "Allocation error");
return;
}
// transpose cv::Mat if needed
cv::Mat input(mat);
if (input.dims == 2 && transpose)
input = input.t();
// Create a new mxArray (of the specified classID) equivalent to cv::Mat
const mwSize nchannels = input.channels();
const int* dims_ = input.size;
std::vector<mwSize> d(dims_, dims_ + input.dims);
d.push_back(nchannels); // mxCreate* ignores trailing singleton dimensions
std::swap(d[0], d[1]);
if (classid == mxLOGICAL_CLASS) {
// OpenCV's logical true is any nonzero, while MATLAB's true is 1.
cv::compare(input, 0, input, cv::CMP_NE);
input.setTo(1, input);
p_ = mxCreateLogicalArray(d.size(), &d[0]);
}
else
p_ = mxCreateNumericArray(d.size(), &d[0], classid, mxREAL);
if (!p_)
mexErrMsgIdAndTxt("mexopencv:error", "Allocation error");
// split input cv::Mat into several single-channel arrays
std::vector<cv::Mat> channels;
channels.reserve(nchannels);
cv::split(input, channels);
// Copy each channel from Mat to mxArray (converting to specified classid),
// as in: p_(:,:,i) <- cast_to_classid_type(channels[i])
std::vector<mwSize> si(d.size(), 0); // subscript index
const int type = CV_MAKETYPE(DepthOf[classid], 1); // destination type
for (mwIndex i = 0; i < nchannels; ++i) {
si[si.size() - 1] = i; // last dim is a channel index
void *ptr = reinterpret_cast<void*>(
reinterpret_cast<size_t>(mxGetData(p_)) +
mxGetElementSize(p_) * subs(si)); // ptr to i-th channel data
cv::Mat m(input.dims, dims_, type, ptr); // only creates Mat header
channels[i].convertTo(m, type); // Write to mxArray through m
}
}
#else
// works for any cv::Mat/cv::MatND (any combination of channels and dimensions)
MxArray::MxArray(const cv::Mat& mat, mxClassID classid, bool)
{
// determine classID of output array
classid = (classid == mxUNKNOWN_CLASS) ? ClassIDOf[mat.depth()] : classid;
// handle special case of empty input Mat by returning 0x0 array
if (mat.empty()) {
// TODO: maybe return empty array of same dimensions 0x1, 1x0x2, ...
p_ = mxCreateNumericMatrix(0, 0, classid, mxREAL);
if (!p_)
mexErrMsgIdAndTxt("mexopencv:error", "Allocation error");
return;
}
// Create output mxArray (of specified type), equivalent to the input Mat
const mwSize cn = mat.channels();
const mwSize len = mat.
没有合适的资源?快使用搜索试试~ 我知道了~
已编译好的opencv库,适用于matlab
共2257个文件
m:1137个
cpp:459个
mexw64:452个
3星 · 超过75%的资源 需积分: 0 274 下载量 114 浏览量
2022-06-26
08:49:16
上传
评论 6
收藏 63.48MB RAR 举报
温馨提示
已编译好的opencv库,适用于matlab
资源详情
资源评论
资源推荐
收起资源包目录
已编译好的opencv库,适用于matlab (2257个子文件)
MxArray.cpp 39KB
mexopencv_features2d.cpp 38KB
mexopencv_videostab.cpp 36KB
Dataset_.cpp 35KB
mexopencv_stitching.cpp 32KB
Utils_.cpp 25KB
Net_.cpp 20KB
SuperResolution_.cpp 19KB
Retina_.cpp 19KB
HOGDescriptor_.cpp 19KB
Facemark_.cpp 17KB
DisparityWLSFilter_.cpp 17KB
SVM_.cpp 16KB
BinaryDescriptor_.cpp 15KB
mexopencv_aruco.cpp 14KB
AffineFeature2D_.cpp 13KB
RTrees_.cpp 12KB
ANN_MLP_.cpp 12KB
cvtColor.cpp 12KB
PCTSignatures_.cpp 12KB
EM_.cpp 12KB
Boost_.cpp 11KB
VideoWriter_.cpp 11KB
Stitcher_.cpp 11KB
SelectiveSearchSegmentation_.cpp 10KB
DescriptorMatcher_.cpp 10KB
mexopencv_shape.cpp 10KB
DetectionBasedTracker_.cpp 10KB
Rect_.cpp 10KB
AKAZE_.cpp 10KB
DTrees_.cpp 10KB
ConjGradSolver_.cpp 10KB
SVMSGD_.cpp 10KB
ORB_.cpp 10KB
BinaryDescriptorMatcher_.cpp 10KB
BasicFaceRecognizer_.cpp 10KB
KAZE_.cpp 10KB
StereoBM_.cpp 9KB
LogisticRegression_.cpp 9KB
SURF_.cpp 9KB
TransientAreasSegmentationModule_.cpp 9KB
LBPHFaceRecognizer_.cpp 9KB
KNearest_.cpp 8KB
FileStorage.cpp 8KB
CascadeClassifier_.cpp 8KB
StructuredEdgeDetection_.cpp 8KB
GeneralizedHoughGuil_.cpp 8KB
ImgHash_.cpp 8KB
FacemarkKazemi_.cpp 8KB
LSDDetector_.cpp 8KB
StereoSGBM_.cpp 8KB
ShapeTransformer_.cpp 8KB
ContourFitting_.cpp 8KB
ShapeContextDistanceExtractor_.cpp 8KB
VideoCapture_.cpp 8KB
EdgeBoxes_.cpp 8KB
SIFT_.cpp 8KB
DownhillSolver_.cpp 8KB
BRISK_.cpp 8KB
NormalBayesClassifier_.cpp 7KB
BackgroundSubtractorMOG2_.cpp 7KB
HfsSegment_.cpp 7KB
findCirclesGrid.cpp 7KB
Blender_.cpp 7KB
DISOpticalFlow_.cpp 7KB
BackgroundSubtractorGMG_.cpp 7KB
AdaptiveManifoldFilter_.cpp 7KB
MSER_.cpp 7KB
mexopencv_ml.cpp 7KB
TwoPassStabilizer_.cpp 7KB
BackgroundSubtractorLSBP_.cpp 7KB
DAISY_.cpp 7KB
GFTTDetector_.cpp 7KB
LineSegmentDetector_.cpp 7KB
VariationalRefinement_.cpp 7KB
DualTVL1OpticalFlow_.cpp 7KB
GeneralizedHoughBallard_.cpp 6KB
BackgroundSubtractorKNN_.cpp 6KB
BackgroundSubtractorGSOC_.cpp 6KB
Plot2d_.cpp 6KB
Subdiv2D_.cpp 6KB
AlignMTB_.cpp 6KB
OnePassStabilizer_.cpp 6KB
AgastFeatureDetector_.cpp 6KB
FastFeatureDetector_.cpp 6KB
VGG_.cpp 6KB
stereoCalibrate.cpp 6KB
GPCForest_.cpp 6KB
imwrite.cpp 6KB
BackgroundSubtractorCNT_.cpp 6KB
TonemapDurand_.cpp 6KB
BackgroundSubtractorMOG_.cpp 6KB
SuperpixelSLIC_.cpp 6KB
DTFilter_.cpp 6KB
FeatureDetector_.cpp 6KB
MergeMertens_.cpp 6KB
TonemapReinhard_.cpp 6KB
SuperpixelSEEDS_.cpp 6KB
CalibrateDebevec_.cpp 6KB
BoostDesc_.cpp 6KB
共 2257 条
- 1
- 2
- 3
- 4
- 5
- 6
- 23
很简单的猫
- 粉丝: 5
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1