cv::Mat MxArray::toMat(int depth, bool transpose) const { // Create cv::Mat object. std::vector<int> d(dims(), dims()+ndims()); int ndims = (d.size()>2) ? d.size()-1 : d.size(); int nchannels = (d.size()>2) ? *(d.end()-1) : 1; depth = (depth==CV_USRTYPE1) ? DepthOf[classID()] : depth; std::swap(d[0], d[1]); cv::Mat mat(ndims, &d[0], CV_MAKETYPE(depth, nchannels)); // Copy each channel. std::vector<cv::Mat> channels(nchannels); std::vector<mwSize> si(d.size(), 0); // subscript index int type = CV_MAKETYPE(DepthOf[classID()], 1); // Source type for (int i = 0; i<nchannels; ++i) { si[d.size()-1] = i; void *pd = reinterpret_cast<void*>( reinterpret_cast<size_t>(mxGetData(p_))+ mxGetElementSize(p_)*subs(si)); cv::Mat m(ndims, &d[0], type, pd); // Read from mxArray through m m.convertTo(channels[i], CV_MAKETYPE(depth, 1)); } cv::merge(channels, mat); return (mat.dims==2 && transpose) ? cv::Mat(mat.t()) : mat; }
cv::Mat MxArray::toMat(int depth, bool transpose) const { // Create cv::Mat object (of the specified depth), equivalent to mxArray std::vector<int> d(dims(), dims()+ndims()); const mwSize ndims = (d.size()>2) ? d.size()-1 : d.size(); const mwSize nchannels = (d.size()>2) ? d.back() : 1; depth = (depth == CV_USRTYPE1) ? DepthOf[classID()] : depth; std::swap(d[0], d[1]); cv::Mat mat(ndims, &d[0], CV_MAKETYPE(depth, nchannels)); // Copy each channel from mxArray to Mat (converting to specified depth), // as in: channels[i] <- cast_to_mat_depth(p_(:,:,i)) std::vector<cv::Mat> channels(nchannels); std::vector<mwSize> si(d.size(), 0); // subscript index const int type = CV_MAKETYPE(DepthOf[classID()], 1); // Source type for (mwIndex i = 0; i<nchannels; ++i) { si[si.size() - 1] = i; // last dim is a channel idx void *pd = reinterpret_cast<void*>( reinterpret_cast<size_t>(mxGetData(p_)) + mxGetElementSize(p_)*subs(si)); // ptr to i-th channel data const cv::Mat m(ndims, &d[0], type, pd); // only creates Mat headers // Read from mxArray through m, writing into channels[i] m.convertTo(channels[i], CV_MAKETYPE(depth, 1)); } // Merge channels back into one cv::Mat array cv::merge(channels, mat); // transpose cv::Mat if needed if (mat.dims==2 && transpose) mat = mat.t(); return mat; }
cv::MatND MxArray::toMatND(int depth, bool transpose) const { // Create cv::Mat object. std::vector<int> d(dims(), dims()+ndims()); std::swap(d[0], d[1]); cv::MatND m(ndims(), &d[0], CV_MAKETYPE(DepthOf[classID()], 1), mxGetData(p_)); // Copy. cv::MatND mat; depth = (depth==CV_USRTYPE1) ? CV_MAKETYPE(DepthOf[classID()], 1) : depth; m.convertTo(mat, CV_MAKETYPE(depth, 1)); return (mat.dims==2 && transpose) ? cv::Mat(mat.t()) : mat; }
cv::MatND MxArray::toMatND(int depth, bool transpose) const { // Create cv::MatND object (of the specified depth), equivalent to mxArray std::vector<int> d(dims(), dims()+ndims()); std::swap(d[0], d[1]); depth = (depth == CV_USRTYPE1) ? DepthOf[classID()] : depth; cv::MatND mat(d.size(), &d[0], CV_MAKETYPE(depth, 1)); // Copy from mxArray to cv::MatND (converting to specified depth) const int type = CV_MAKETYPE(DepthOf[classID()], 1); // source type const cv::MatND m(d.size(), &d[0], type, mxGetData(p_)); // only Mat header // Read from mxArray through m, writing into mat m.convertTo(mat, CV_MAKETYPE(depth, 1)); // transpose cv::MatND if needed if (mat.dims==2 && transpose) mat = mat.t(); return mat; }
#include "theactivex.h" QAXFACTORY_DEFAULT( TheActiveX, // widget class "{01234567-89AB-CDEF-0123-456789ABCDEF}", // class ID "{01234567-89AB-CDEF-0123-456789ABCDEF}", // interface ID "{01234567-89AB-CDEF-0123-456789ABCDEF}", // event interface ID "{01234567-89AB-CDEF-0123-456789ABCDEF}", // type library ID "{01234567-89AB-CDEF-0123-456789ABCDEF}" // application ID ) //! [2] //! [3] settings->setValue("/CLSID/" + classID(key) + "/Implemented Categories/" + "/{00000000-0000-0000-000000000000}/.", QString()); //! [3] //! [4] settings->remove("/CLSID/" + classID(key) + "/Implemented Categories" + "/{00000000-0000-0000-000000000000}/."); //! [4] //! [5] int main(int argc, char *argv[])