資源簡介
matlab2015(2016可用)利用mex編譯opencv249中的warpPerspective函數(shù),簡化和加速roi的提取。http://blog.csdn.net/sunflower_boy/article/details/51137605

代碼片段和文件信息
#include?“mex.h“
#include?“matrix.h“
#include?“math.h“
#include?“opencv2/opencv.hpp“
using?namespace?cv;
void?mexFunction(int?nlhs?mxArray?*plhs[]?int?nrhs?const?mxArray?*prhs[])
{
????int?N?=?mxGetN(prhs[0]);//number?of?cols
????int?M?=?mxGetM(prhs[0]);//number?of?rows
????char*?srcPtr?=?(char*)mxGetData(prhs[0]);?
????double*?pointPtr?=?mxGetPr(prhs[1]);
????double?dstSizeW?=?0;
????double?dstSizeH?=?0;
????double?x1?=?*(pointPtr+0);
????double?x2?=?*(pointPtr+1);
????double?x3?=?*(pointPtr+2);
????double?x4?=?*(pointPtr+3);
????double?y1?=?*(pointPtr+4);
????double?y2?=?*(pointPtr+5);
????double?y3?=?*(pointPtr+6);
????double?y4?=?*(pointPtr+7);
????Point2f?src_vertices[4];//Point2f(xy)
????src_vertices[0]?=?Point2f(x1y1);
????src_vertices[1]?=?Point2f(x2y2);
????src_vertices[2]?=?Point2f(x3y3);
????src_vertices[3]?=?Point2f(x4y4);
????mexPrintf(“src_Vertice:?xy\n“);
????mexPrintf(“%f%f;\n“src_vertices[0].xsrc_vertices[0].y);
????mexPrintf(“%f%f;\n“src_vertices[1].xsrc_vertices[1].y);
????mexPrintf(“%f%f;\n“src_vertices[2].xsrc_vertices[2].y);
????mexPrintf(“%f%f;\n“src_vertices[3].xsrc_vertices[3].y);
????
????Point2f?dst_vertices[4];
????if(nrhs==3)
????{
????????double*?dstPointPtr?=?mxGetPr(prhs[2]);
????????dst_vertices[0]?=?Point2f(*(dstPointPtr+0)*(dstPointPtr+4));
????????dst_vertices[1]?=?Point2f(*(dstPointPtr+1)*(dstPointPtr+5));
????????dst_vertices[2]?=?Point2f(*(dstPointPtr+2)*(dstPointPtr+6));
????????dst_vertices[3]?=?Point2f(*(dstPointPtr+3)*(dstPointPtr+7));
????}
????else?
????{
????????mexPrintf(“Auto?Dst?Point:\n“);???
????????double?dstSize1?=?sqrt(pow((x2-x1)2)+pow((y2-y1)2));
????????double?dstSize2?=?sqrt(pow((x3-x2)2)+pow((y3-y2)2));
????????
????????if(dstSize1?>?dstSize2)
????????{
????????????dstSizeW?=?dstSize1;
????????????dstSizeH?=?dstSize2;
????????????dst_vertices[0]?=?Point2f(dstSizeW0);
????????????dst_vertices[1]?=?Point2f(00);
????????????dst_vertices[2]?=?Point2f(0dstSizeH);
????????????dst_vertices[3]?=?Point2f(dstSizeWdstSizeH);?
????????}
????????else
????????{
????????????dstSizeW?=?dstSize2;
????????????dstSizeH?=?dstSize1;
????????????dst_vertices[0]?=?Point2f(00);
????????????dst_vertices[1]?=?Point2f(0dstSizeH);
????????????dst_vertices[2]?=?Point2f(dstSizeWdstSizeH);
????????????dst_vertices[3]?=?Point2f(dstSizeW0);?
????????}
????????mexPrintf(“dstSizeWdstSizeH:%f%f\n“dstSizeWdstSizeH);
????????mexPrintf(“dst_Vertice:?xy\n“);
????????mexPrintf(“%f%f;\n“dst_vertices[0].xdst_vertices[0].y);
????????mexPrintf(“%f%f;\n“dst_vertices[1].xdst_vertices[1].y);
????????mexPrintf(“%f%f;\n“dst_vertices[2].xdst_vertices[2].y);
????????mexPrintf(“%f%f;\n“dst_vertices[3].xdst_vertices[3].y);
????
????}
????//Acturally?it?should?be?Mat(rowscols...);
????//but?Matlab?Array?is?store?by?cols
????Mat?src?=?Mat(NMCV_8UC1srcPtr);
????//transposition?because?Matlab?Array?store?by?col
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????3536??2016-04-12?21:50??cv_rotateRect.cpp
?????文件??????12800??2016-04-12?21:50??cv_rotateRect.mexw64
-----------?---------??----------?-----??----
????????????????16336????????????????????2
- 上一篇:JPEG編解碼程序
- 下一篇:Matlab-PDE工具箱有限元法求解偏微分方程
評(píng)論
共有 條評(píng)論