Repository: opencv
Issue: cv.imread() causes Matlab segfault
Labels: bug,auto-transferred,priority: normal,affected: 3.4,category: matlab bindings

Transferred from http://code.opencv.org/issues/4201

```
|| Henry Braun on 2015-02-17 18:19
|| Priority: Normal
|| Affected: branch 'master' (3.0-dev)
|| Category: matlab bindings
|| Tracker: Bug
|| Difficulty: 
|| PR: 
|| Platform: x64 / Mac OSX
```
## cv.imread() causes Matlab segfault

```
I'm running Matlab r2014b on Mac OS 10.10.1.  Official OpenCV bindings from opencv_contrib appeared to build and install perfectly.

I am running this line of code:
<pre>
im = cv.imread('peppers.png');
</pre>

This produces a segmentation violation and crashes Matlab.  This also happens with other Matlab test images ('cameraman.tif', 'football.jpg') but does not occur when I try it with one of my own images.  Copying the test images from within matlab_r2014b.app to my desktop and loading from there does not fix the problem.

Matlab output is below:
<pre>
------------------------------------------------------------------------
       Segmentation violation detected at Tue Feb 17 10:53:27 2015
------------------------------------------------------------------------

Configuration:
  Crash Decoding     : Disabled
  Current Visual     : Quartz
  Default Encoding   : ISO-8859-1
  MATLAB Architecture: maci64
  MATLAB Root        : /Applications/MATLAB_R2014b.app
  MATLAB Version     : 8.4.0.150421 (R2014b)
  Operating System   : Darwin 14.0.0 Darwin Kernel Version 14.0.0: Fri Sep 19 00:26:44 PDT 2014; root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
  Processor ID       : x86 Family 6 Model 69 Stepping 1, GenuineIntel
  Software OpenGL    : 0
  Virtual Machine    : Java 1.7.0_55-b13 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
  Window System      : Quartz

Fault Count: 1


Abnormal termination:
Segmentation violation

Register State (from fault):
  RAX = 0000000000001002  RBX = 0000000000001400
  RCX = 000000010f968af0  RDX = 0000000000001400
  RSP = 00007fff9c01be68  RBP = 0000000000001002
  RSI = 0000000101d3c000  RDI = 0000000000001002

   R8 = ff80000000001002   R9 = 0000000000000000
  R10 = 000000010f968adc  R11 = 000000010f968ae0
  R12 = 000000010f968af0  R13 = 0000000134a644f9
  R14 = ffffffffffffffff  R15 = 00007fff9c01be68

  RIP = 00007fff7e4aa0c8  RFL = 0000000000000000

   CS = 0000000135095940   FS = 000000010f968f80   GS = 00007fff7ce5d1d8

Stack Trace (from fault):
[  0] 0x000000010281ae64 /Applications/MATLAB_R2014b.app/bin/maci64/libmwfl.dylib+00028260 _ZN2fl4diag15stacktrace_base7captureERKNS0_14thread_contextEm+00000052
[  1] 0x000000010281ea2a /Applications/MATLAB_R2014b.app/bin/maci64/libmwfl.dylib+00043562 _ZN2fl4test17terminate_handledEv+00000906
[  2] 0x000000010281e477 /Applications/MATLAB_R2014b.app/bin/maci64/libmwfl.dylib+00042103 _ZN2fl4diag13terminate_logEPKcPK17__darwin_ucontext+00000119
[  3] 0x0000000102272b7a /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcr.dylib+00387962 _Z32mnRunPathDependentInitializationv+00003146
[  4] 0x0000000102272e58 /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcr.dylib+00388696 _Z32mnRunPathDependentInitializationv+00003880
[  5] 0x0000000102270733 /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcr.dylib+00378675 mnFatalSignalHandler+00000275
[  6] 0x00007fff8dce5f1a           /usr/lib/system/libsystem_platform.dylib+00020250 _sigtramp+00000026
[  7] 0x5800000102d3b517                                   <unknown-module>+00000000
[  8] 0x0000000134a5ba64 /Users/henry/Downloads/opencv-3.0.0-beta/staticLibs/lib/libopencv_core.3.0.dylib+01313380 _ZN2cv9transposeERKNS_11_InputArrayERKNS_12_OutputArrayE+00000052
[  9] 0x000000012263f409             /usr/local/matlab/+cv/imread.mexmaci64+00238601 _ZN2cv6bridge20deepCopyAndTransposeIhhEEvRKNS_3MatERN6matlab7MxArrayE+00000665
[ 10] 0x0000000122607f9c             /usr/local/matlab/+cv/imread.mexmaci64+00012188 _ZN2cv6bridge6Bridge7FromMatIhEEN6matlab7MxArrayERKNS_3MatE+00000204
[ 11] 0x0000000122606e8c             /usr/local/matlab/+cv/imread.mexmaci64+00007820 _ZN2cv6bridge6Bridge7FromMatIN6matlab11InheritTypeEEENS3_7MxArrayERKNS_3MatE+00000156
[ 12] 0x00000001226075d1             /usr/local/matlab/+cv/imread.mexmaci64+00009681 mexFunction+00001201
[ 13] 0x00000001072faeeb /Applications/MATLAB_R2014b.app/bin/maci64/libmex.dylib+00069355 mexRunMexFile+00000091
[ 14] 0x00000001072f6f41 /Applications/MATLAB_R2014b.app/bin/maci64/libmex.dylib+00053057 _ZN7Mfh_mex30runMexFileWithSignalProtectionEiPP11mxArray_tagiS2_+00000113
[ 15] 0x00000001072f7130 /Applications/MATLAB_R2014b.app/bin/maci64/libmex.dylib+00053552 _ZN7Mfh_mex13dispatch_fileEiPP11mxArray_tagiS2_+00000304
[ 16] 0x0000000107386c28 /Applications/MATLAB_R2014b.app/bin/maci64/libmwm_dispatcher.dylib+00400424 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+00000600
[ 17] 0x000000010756ae8e /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcos.dylib+01093262 _ZNK4mcos17MScopedMethodInfo6invokeEPKNS_9COSClientERiPNS_8COSValueEiPKS5_+00000606
[ 18] 0x0000000107508597 /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcos.dylib+00689559 _ZN24OpaqueMethodCallMetaData11callMMethodEPN4mcos13COSMethodInfoEPP11mxArray_tagPKNS0_9COSClientE+00000359
[ 19] 0x000000010750be63 /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcos.dylib+00704099 _ZN24OpaqueMethodCallMetaData23callMethodOrConstructorEP11mxArray_tagbiPS1_iPPKS0_bPKN4mcos9COSClientEPS9_PPNS6_13COSMethodInfoE+00000259
[ 20] 0x000000010750ad41 /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcos.dylib+00699713 _Z22omCallMethodWithClientP11mxArray_tagbS0_iPS0_iPPKS_PKN4mcos9COSClientEPS8_PPNS5_13COSMethodInfoE+00000417
[ 21] 0x0000000107596ee8 /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcos.dylib+01273576 _Z18omCallStaticMethodP11mxArray_tagiPS0_iPPKS_+00000088
[ 22] 0x000000010761fe64 /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcos.dylib+01834596 _ZN17Mfh_opaque_static11dispatch_mfEiPP11mxArray_tagiS2_+00000116
[ 23] 0x000000010732a12d /Applications/MATLAB_R2014b.app/bin/maci64/libmwm_dispatcher.dylib+00020781 _ZN13Mfh_MATLAB_fn11dispatch_fhEiPP11mxArray_tagiS2_+00000333
[ 24] 0x000000010761cacc /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcos.dylib+01821388 _ZN10Mfh_opaque11dispatch_fhEiPP11mxArray_tagiS2_+00000028
[ 25] 0x0000000107ceed62 /Applications/MATLAB_R2014b.app/bin/maci64/libmwm_interpreter.dylib+01523042 _Z19inDispatchFromStackiPKcii+00001650
[ 26] 0x0000000107c90dd8 /Applications/MATLAB_R2014b.app/bin/maci64/libmwm_interpreter.dylib+01138136 inPcodeWalker+00022552
[ 27] 0x0000000107c8d917 /Applications/MATLAB_R2014b.app/bin/maci64/libmwm_interpreter.dylib+01124631 inPcodeWalker+00009047
[ 28] 0x0000000107c88fb7 /Applications/MATLAB_R2014b.app/bin/maci64/libmwm_interpreter.dylib+01105847 inInterPcode+00000935
[ 29] 0x0000000107c8a1c6 /Applications/MATLAB_R2014b.app/bin/maci64/libmwm_interpreter.dylib+01110470 _Z26inExecuteMFunctionOrScriptP6Mfh_mpb+00000886
[ 30] 0x0000000107d2c1f1 /Applications/MATLAB_R2014b.app/bin/maci64/libmwm_interpreter.dylib+01774065 _Z10inRunMfileiPP11mxArray_tagiS1_P6Mfh_mpP15inWorkSpace_tag+00002337
[ 31] 0x0000000107386c55 /Applications/MATLAB_R2014b.app/bin/maci64/libmwm_dispatcher.dylib+00400469 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+00000645
[ 32] 0x0000000107ccf48b /Applications/MATLAB_R2014b.app/bin/maci64/libmwm_interpreter.dylib+01393803 _Z23inEvalPcodeHeaderToWordP15_memory_contextiPP11mxArray_tagP12_pcodeheaderP6Mfh_mpj+00000219
[ 33] 0x0000000107c81f4b /Applications/MATLAB_R2014b.app/bin/maci64/libmwm_interpreter.dylib+01077067 _Z25in_local_call_with_setjmpIN5boost3_bi6bind_tIvPFvP15_memory_contextPiPP11mxArray_tagP12_pcodeheaderjENS1_5list5INS1_5valueIS4_EENS0_3argILi1EEENSG_ILi2EEENSE_ISA_EENSE_IiEEEEEEEN6mlutil14cmddistributor17inExecutionStatusET_S5_S8_b+00000171
[ 34] 0x0000000107c7d221 /Applications/MATLAB_R2014b.app/bin/maci64/libmwm_interpreter.dylib+01057313 _Z12inEvalStringP15_memory_contextRKSbItSt11char_traitsItESaItEE8EvalTypeiPP11mxArray_tag12inDebugCheckP12_pcodeheaderPib+00002769
[ 35] 0x0000000107c7d7cd /Applications/MATLAB_R2014b.app/bin/maci64/libmwm_interpreter.dylib+01058765 _ZN12InterpBridge22EvalCmdWithLocalReturnERKSbItSt11char_traitsItESaItEEPibb+00000141
[ 36] 0x000000010728f11d /Applications/MATLAB_R2014b.app/bin/maci64/libmwbridge.dylib+00061725 _Z28evalCommandWithLongjmpSafetyRKSbItSt11char_traitsItESaItEE+00000093
[ 37] 0x000000010728f804 /Applications/MATLAB_R2014b.app/bin/maci64/libmwbridge.dylib+00063492 _Z8mnParserv+00000772
[ 38] 0x000000010225a832 /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcr.dylib+00288818 _ZN11mcrInstance30mnParser_on_interpreter_threadEv+00000034
[ 39] 0x00000001022350d1 /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcr.dylib+00135377 _ZN3mcr7runtime17InterpreterThread4Impl22TypedInvocationRequestIvE29doNotRethrowMxArrayExceptionsERKN5boost8functionIFvvEEE+00000033
[ 40] 0x0000000102235d89 /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcr.dylib+00138633 _ZN5boost6detail11task_objectIvNS_3_bi6bind_tIvPFvRKNS_8functionIFvvEEEENS2_5list1INS2_5valueIS6_EEEEEEE6do_runEv+00000025
[ 41] 0x0000000102235586 /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcr.dylib+00136582 _ZN5boost6detail9task_baseIvE3runEv+00000166
[ 42] 0x0000000102235377 /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcr.dylib+00136055 _ZN3mcr7runtime17InterpreterThread4Impl22TypedInvocationRequestIvE3runEv+00000023
[ 43] 0x0000000102230f90 /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcr.dylib+00118672 _ZN3mcr7runtime17InterpreterThread4Impl26invocation_request_handlerEl+00000032
[ 44] 0x0000000101d70005 /Applications/MATLAB_R2014b.app/bin/maci64/libmwservices.dylib+00196613 _ZN10eventqueue18UserEventQueueImpl5flushEv+00001205
[ 45] 0x000000010874da65 /Applications/MATLAB_R2014b.app/bin/maci64/libmwuix.dylib+00043621 _Z25isHandleUserEventCallbackPFvPvE+00000501
[ 46] 0x0000000101e3fa45 /Applications/MATLAB_R2014b.app/bin/maci64/libmwservices.dylib+01047109 _Z21svWS_ProcessCallbacksv+00016693
[ 47] 0x0000000101e3b152 /Applications/MATLAB_R2014b.app/bin/maci64/libmwservices.dylib+01028434 _Z25svWS_ProcessPendingEventsiib+00000834
[ 48] 0x0000000101e3ae5e /Applications/MATLAB_R2014b.app/bin/maci64/libmwservices.dylib+01027678 _Z25svWS_ProcessPendingEventsiib+00000078
[ 49] 0x000000010223118f /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcr.dylib+00119183 _ZN3mcr7runtime17InterpreterThread4Impl14process_eventsERKN5boost10shared_ptrIS2_EE+00000095
[ 50] 0x000000010223149f /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcr.dylib+00119967 _ZN3mcr7runtime17InterpreterThread4Impl3runERKN5boost10shared_ptrIS2_EEPNS2_12init_contextE+00000335
[ 51] 0x0000000102217d1b /Applications/MATLAB_R2014b.app/bin/maci64/libmwmcr.dylib+00015643 _Z26run_init_and_handle_eventsPv+00000059
[ 52] 0x00007fff9c01d2fc            /usr/lib/system/libsystem_pthread.dylib+00013052 _pthread_body+00000131
[ 53] 0x00007fff9c01d279            /usr/lib/system/libsystem_pthread.dylib+00012921 _pthread_body+00000000
[ 54] 0x00007fff9c01b4b1            /usr/lib/system/libsystem_pthread.dylib+00005297 thread_start+00000013


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.

If this problem is reproducible, please submit a Service Request via:
    http://www.mathworks.com/support/contact_us/

A technical support engineer might contact you with further information.

Thank you for your help.
</pre>
```
## History
##### Vadim Pisarevsky on 2015-04-27 11:32

```
-   Category set to highgui-images
```
##### Vadim Pisarevsky on 2015-05-22 07:26

```
-   Category changed from highgui-images to matlab bindings
```