matlab+OpenCV3.4.1调用fast后,vector就访问冲突了

#include "mex.h"
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\features2d\features2d.hpp>
#include <core\mat.hpp>


using namespace std;
using namespace cv;


void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (nrhs == 1)
{
int n = mxGetNumberOfDimensions(prhs[0]);
        
size_t M = mxGetM(prhs[0]);
size_t N = mxGetN(prhs[0]) / n;
uchar *imgData = NULL;
if (mxIsUint8(prhs[0]) && n == 3) //元素类型 与 维数
{
imgData = (uchar *)mxGetPr(prhs[0]);
Mat image(M, N, CV_8UC3); //创建三通道Mat类
int subs[3];
for (int i = 0; i < M; i++)
{
subs[0] = i;
for (int j = 0; j < N; j++)
{
subs[1] = j;
for (int k = 0; k < 3; k++)
{
subs[2] = (k & 1) ? 1 : abs(k-2);   //Mat为BGR
int index = (int)mxCalcSingleSubscript(prhs[0], 3, subs);
image.row(i).col(j).data[k] = imgData[index];
}
}
}
                imshow("temp.jpg", image);
                        vector<KeyPoint> keypoints;    //KeyPoint是opencv中定义的特征点类
                  Ptr<FeatureDetector> fast = FastFeatureDetector::create(20);
                fast->detect(image, keypoints);  //就是这行导致的,不知道怎么办?????????????
                        for (size_t i = 0; i < keypoints.size(); i++)//在keypoints.size()崩溃
                        {
                                   circle(image, Point(keypoints[i].pt.x, keypoints[i].pt.y), 2, Scalar(0, 255, 0),1);
                        }
                        //imshow("temp0.jpg", image);
                        keypoints.clear();//也可使其崩溃
                }
        }
return;
}
用mex编译时没有出错,但运行时,代码中只要出现STL的vector的操作就崩溃,说是访问冲突,但在vs中没有错误。


matlab的错误提示:(没多大用)
------------------------------------------------------------------------
          Access violation detected at Sun Jun 17 16:56:20 2018
------------------------------------------------------------------------


Configuration:
  Crash Decoding      : Disabled
  Crash Mode          : continue (default)
  Current Graphics Driver: Unknown hardware 
  Default Encoding    : GBK
  Graphics card 1     : Advanced Micro Devices, Inc. ( 0x1002 ) Radeon (TM) R7 M445 Version 23.20.768.12
  Graphics card 2     : Intel Corporation ( 0x8086 ) Intel(R) HD Graphics 620 Version 22.20.16.4836
  Host Name           : DESKTOP-ND8A7MB
  MATLAB Architecture : win64
  MATLAB Root         : E:\Program Files\MATLAB\R2016a
  MATLAB Version      : 9.0.0.341360 (R2016a)
  OpenGL              : hardware
  Operating System    : Microsoft Windows 10 家庭中文版
  Processor ID        : x86 Family 6 Model 142 Stepping 9, GenuineIntel
  Virtual Machine     : Java 1.7.0_60-b19 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
  Window System       : Version 10.0 (Build 16299)


Fault Count: 1




Abnormal termination:
Access violation


Register State (from fault):
  RAX = 000000000000001c  RBX = 000000000d10b3d0
  RCX = 00000000043fad28  RDX = 00000000043fad28
  RSP = 00000000043f9bb0  RBP = 00000000043fb330
  RSI = 0000000044140450  RDI = 00000000043f9be0
 
   R8 = 00000000043fad28   R9 = 000000000d0898aa
  R10 = 000000000d0385c0  R11 = 000000000d089500
  R12 = 0000000000000001  R13 = 0000000000000244
  R14 = 00000000ffffffff  R15 = 0000000000000000
 
  RIP = 00007ff807f54119  EFL = 00010206
 
   CS = 0033   FS = 0053   GS = 002b


Stack Trace (from fault):
[  0] 0x00007ff807f54119  E:\opencv\build\x64\vc14\bin\opencv_world341d.dll+49234201 cv::directx::convertFromD3D10Texture2D+48768785
[  1] 0x00007ff807f57d35  E:\opencv\build\x64\vc14\bin\opencv_world341d.dll+49249589 cv::directx::convertFromD3D10Texture2D+48784173
[  2] 0x00007ff808297cb4  E:\opencv\build\x64\vc14\bin\opencv_world341d.dll+52657332 cv::directx::convertFromD3D10Texture2D+52191916
[  3] 0x00007ff808297d44  E:\opencv\build\x64\vc14\bin\opencv_world341d.dll+52657476 cv::directx::convertFromD3D10Texture2D+52192060
[  4] 0x00007ff808297c34  E:\opencv\build\x64\vc14\bin\opencv_world341d.dll+52657204 cv::directx::convertFromD3D10Texture2D+52191788
[  5] 0x00007ff808e9787d  E:\opencv\build\x64\vc14\bin\opencv_world341d.dll+65239165 cv::directx::convertFromD3D10Texture2D+64773749
[  6] 0x00007ff808efeb5e  E:\opencv\build\x64\vc14\bin\opencv_world341d.dll+65661790 cv::directx::convertFromD3D10Texture2D+65196374
[  7] 0x00007ff808f03c98  E:\opencv\build\x64\vc14\bin\opencv_world341d.dll+65682584 cv::directx::convertFromD3D10Texture2D+65217168
[  8] 0x00007ff808f04202  E:\opencv\build\x64\vc14\bin\opencv_world341d.dll+65683970 cv::directx::convertFromD3D10Texture2D+65218554
[  9] 0x00007ff8414516ea      H:\MATLAB\video_Motion_Saturation\Fast.mexw64+00005866 mexFunction+00000970
[ 10] 0x00000000fc5f77d1 E:\Program Files\MATLAB\R2016a\bin\win64\libmex.dll+00096209 mexRunMexFile+00000129
[ 11] 0x00000000fc5f6d12 E:\Program Files\MATLAB\R2016a\bin\win64\libmex.dll+00093458 inSwapMexfileReader+00000434
[ 12] 0x00000000fc5f6966 E:\Program Files\MATLAB\R2016a\bin\win64\libmex.dll+00092518 mexUnlock+00004774
[ 13] 0x000000001bbf5d1f E:\Program Files\MATLAB\R2016a\bin\win64\m_dispatcher.dll+00089375 Mfh_file::dispatch_fh_impl+00000527
[ 14] 0x000000001bbf5f0e E:\Program Files\MATLAB\R2016a\bin\win64\m_dispatcher.dll+00089870 Mfh_file::dispatch_fh+00000062
[ 15] 0x000000001bbf3e15 E:\Program Files\MATLAB\R2016a\bin\win64\m_dispatcher.dll+00081429 Mfunction_handle::dispatch+00000933
[ 16] 0x000000001c422033 E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+00335923
[ 17] 0x000000001c5c8114 E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+02064660 boost::serialization::singleton<boost::archive::detail::pointer_oserializer<boost::archive::binaryTerm_oarchive,ir::IrTree> >::get_instance+00682852
[ 18] 0x000000001c4a428f E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+00869007 boost::serialization::singleton<boost::archive::detail::pointer_iserializer<boost::archive::binaryTerm_iarchive,ir::IrTree> >::get_instance+00069131
[ 19] 0x000000001c4a4ef6 E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+00872182 boost::serialization::singleton<boost::archive::detail::pointer_iserializer<boost::archive::binaryTerm_iarchive,ir::IrTree> >::get_instance+00072306
[ 20] 0x000000001c4a6237 E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+00877111 boost::serialization::singleton<boost::archive::detail::pointer_iserializer<boost::archive::binaryTerm_iarchive,ir::IrTree> >::get_instance+00077235
[ 21] 0x000000001c4a6c05 E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+00879621 boost::serialization::singleton<boost::archive::detail::pointer_iserializer<boost::archive::binaryTerm_iarchive,ir::IrTree> >::get_instance+00079745
[ 22] 0x000000001c4a642f E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+00877615 boost::serialization::singleton<boost::archive::detail::pointer_iserializer<boost::archive::binaryTerm_iarchive,ir::IrTree> >::get_instance+00077739
[ 23] 0x000000001c4a613a E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+00876858 boost::serialization::singleton<boost::archive::detail::pointer_iserializer<boost::archive::binaryTerm_iarchive,ir::IrTree> >::get_instance+00076982
[ 24] 0x000000001c49de5b E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+00843355 boost::serialization::singleton<boost::archive::detail::pointer_iserializer<boost::archive::binaryTerm_iarchive,ir::IrTree> >::get_instance+00043479
[ 25] 0x000000001c49bd27 E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+00834855 boost::serialization::singleton<boost::archive::detail::pointer_iserializer<boost::archive::binaryTerm_iarchive,ir::IrTree> >::get_instance+00034979
[ 26] 0x000000001c49b1c2 E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+00831938 boost::serialization::singleton<boost::archive::detail::pointer_iserializer<boost::archive::binaryTerm_iarchive,ir::IrTree> >::get_instance+00032062
[ 27] 0x000000001c429d47 E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+00367943
[ 28] 0x000000001c429681 E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+00366209
[ 29] 0x000000001c429810 E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+00366608
[ 30] 0x000000001c5dd395 E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+02151317 boost::serialization::singleton<boost::archive::detail::pointer_oserializer<boost::archive::binaryTerm_oarchive,ir::IrTree> >::get_instance+00769509
[ 31] 0x000000001c5dd31e E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+02151198 boost::serialization::singleton<boost::archive::detail::pointer_oserializer<boost::archive::binaryTerm_oarchive,ir::IrTree> >::get_instance+00769390
[ 32] 0x000000001c3fdad1 E:\Program Files\MATLAB\R2016a\bin\win64\m_lxe.dll+00187089
[ 33] 0x000000001b9a0241 E:\Program Files\MATLAB\R2016a\bin\win64\m_interpreter.dll+00787009 inEvalCmdWithLocalReturn+00000065
[ 34] 0x00000000fb6056cd E:\Program Files\MATLAB\R2016a\bin\win64\libmwbridge.dll+00087757 mnGetPrompt+00005933
[ 35] 0x00000000fb606473 E:\Program Files\MATLAB\R2016a\bin\win64\libmwbridge.dll+00091251 mnParser+00001091
[ 36] 0x000000001b7f99d1   E:\Program Files\MATLAB\R2016a\bin\win64\mcr.dll+00235985 mcr::runtime::setInterpreterThreadToCurrent+00025585
[ 37] 0x000000001b7f8967   E:\Program Files\MATLAB\R2016a\bin\win64\mcr.dll+00231783 mcr::runtime::setInterpreterThreadToCurrent+00021383
[ 38] 0x000000001b7f89e3   E:\Program Files\MATLAB\R2016a\bin\win64\mcr.dll+00231907 mcr::runtime::setInterpreterThreadToCurrent+00021507
[ 39] 0x000000001b7f92d1   E:\Program Files\MATLAB\R2016a\bin\win64\mcr.dll+00234193 mcr::runtime::setInterpreterThreadToCurrent+00023793
[ 40] 0x00000000fd01ea57   E:\Program Files\MATLAB\R2016a\bin\win64\iqm.dll+00584279 iqm::UserEvalPlugin::pre+00030535
[ 41] 0x00000000fd02b3ac   E:\Program Files\MATLAB\R2016a\bin\win64\iqm.dll+00635820 iqm::UserEvalPlugin::pre+00082076
[ 42] 0x00000000fd018bf0   E:\Program Files\MATLAB\R2016a\bin\win64\iqm.dll+00560112 iqm::UserEvalPlugin::pre+00006368
[ 43] 0x00000000fd02ddaa   E:\Program Files\MATLAB\R2016a\bin\win64\iqm.dll+00646570 iqm::UserEvalPlugin::pre+00092826
[ 44] 0x00000000fcffbd07   E:\Program Files\MATLAB\R2016a\bin\win64\iqm.dll+00441607 iqm::PackagedTaskPlugin::PackagedTaskPlugin+00000727
[ 45] 0x00000000fcffc35f   E:\Program Files\MATLAB\R2016a\bin\win64\iqm.dll+00443231 iqm::PackagedTaskPlugin::execute+00000575
[ 46] 0x00000000fcffbd79   E:\Program Files\MATLAB\R2016a\bin\win64\iqm.dll+00441721 iqm::PackagedTaskPlugin::PackagedTaskPlugin+00000841
[ 47] 0x00000000fcffc1d4   E:\Program Files\MATLAB\R2016a\bin\win64\iqm.dll+00442836 iqm::PackagedTaskPlugin::execute+00000180
[ 48] 0x000000001b80b4a5   E:\Program Files\MATLAB\R2016a\bin\win64\mcr.dll+00308389 mcrRegisterExternalFunction+00024629
[ 49] 0x00000000fcfd62ea   E:\Program Files\MATLAB\R2016a\bin\win64\iqm.dll+00287466 iqm::Iqm::setupIqmFcnPtrs+00069674
[ 50] 0x00000000fcfd61d7   E:\Program Files\MATLAB\R2016a\bin\win64\iqm.dll+00287191 iqm::Iqm::setupIqmFcnPtrs+00069399
[ 51] 0x00000000fcfbbae1   E:\Program Files\MATLAB\R2016a\bin\win64\iqm.dll+00178913 iqm::Iqm::deliver+00003409
[ 52] 0x00000000fcfbc9df   E:\Program Files\MATLAB\R2016a\bin\win64\iqm.dll+00182751 iqm::Iqm::deliver+00007247
[ 53] 0x00000001001a14d3 E:\Program Files\MATLAB\R2016a\bin\win64\libmwservices.dll+01774803 services::system_events::PpeDispatchHook::dispatchOne+00031459
[ 54] 0x00000001001ae933 E:\Program Files\MATLAB\R2016a\bin\win64\libmwservices.dll+01829171 sysq::addProcessPendingEventsUnitTestHook+00005491
[ 55] 0x00000001001aeb10 E:\Program Files\MATLAB\R2016a\bin\win64\libmwservices.dll+01829648 sysq::addProcessPendingEventsUnitTestHook+00005968
[ 56] 0x00000001001b0665 E:\Program Files\MATLAB\R2016a\bin\win64\libmwservices.dll+01836645 sysq::getCondition+00003813
[ 57] 0x00000001001b2422 E:\Program Files\MATLAB\R2016a\bin\win64\libmwservices.dll+01844258 svWS_ProcessPendingEvents+00000162
[ 58] 0x000000001b7f9d0d   E:\Program Files\MATLAB\R2016a\bin\win64\mcr.dll+00236813 mcr::runtime::setInterpreterThreadToCurrent+00026413
[ 59] 0x000000001b7fa3fa   E:\Program Files\MATLAB\R2016a\bin\win64\mcr.dll+00238586 mcr::runtime::setInterpreterThreadToCurrent+00028186
[ 60] 0x000000001b7f1a05   E:\Program Files\MATLAB\R2016a\bin\win64\mcr.dll+00203269 mcr_process_events+00008629
[ 61] 0x000000001b7f3462   E:\Program Files\MATLAB\R2016a\bin\win64\mcr.dll+00210018 mcr_process_events+00015378
[ 62] 0x000000001b6f93be E:\Program Files\MATLAB\R2016a\bin\win64\MVMLocal.dll+00234430 mvm_server::inproc::LocalFactory::terminate+00071182
[ 63] 0x00000000fa93cd89   E:\Program Files\MATLAB\R2016a\bin\win64\mvm.dll+01101193 mvm::detail::initLocalMvmHack+00000521
[ 64] 0x00000000fa93d355   E:\Program Files\MATLAB\R2016a\bin\win64\mvm.dll+01102677 mvm::detail::SessionImpl::privateSession+00000373
[ 65] 0x00000000fa93d561   E:\Program Files\MATLAB\R2016a\bin\win64\mvm.dll+01103201 mvm::detail::SessionImpl::privateSession+00000897
[ 66] 0x0000000140006fd5 E:\Program Files\MATLAB\R2016a\bin\win64\MATLAB.exe+00028629
[ 67] 0x0000000140007661 E:\Program Files\MATLAB\R2016a\bin\win64\MATLAB.exe+00030305
[ 68] 0x00007ff85c971fe4                   C:\WINDOWS\System32\KERNEL32.DLL+00073700 BaseThreadInitThunk+00000020
[ 69] 0x00007ff85e1ecb31                      C:\WINDOWS\SYSTEM32\ntdll.dll+00445233 RtlUserThreadStart+00000033




This error was detected while a MEX-file was running. If the MEX-file
is not an official MathWorks function, please examine its source code
for errors. Please consult the External Interfaces Guide for information
on debugging MEX-files.
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值