Repository: opencv
Issue: warpPerspective causing a bus error
Labels: bug,auto-transferred,priority: normal,category: imgproc,category: video,affected: 2.4

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

```
|| Matthieu Tourne on 2014-02-07 19:53
|| Priority: Normal
|| Affected: 2.4.0 - 2.4.7
|| Category: imgproc, video
|| Tracker: Bug
|| Difficulty: 
|| PR: 
|| Platform: x64 / Mac OSX
```
## warpPerspective causing a bus error

```
Hi,

I'm loading a very large image (~600mb), then I use detector+descriptors to find a homography between another image.

Finally, I call `warpPerspective()` to apply my homography on the original image.
This causes a bus error and the error that I pasted below.

Also, calling `warpPerspective()` on the same image, but converted to a grayscale image beforehand works just fine.

I'm using opencv 2.4.7.1 on mac os 10.9, compiled with `--c++11`

Let me know if you need more information on my side!

Best,
Matthieu

<pre>
---- Error and backtrace -----
Process 17741 stopped
* thread #2: tid = 0x743d3, 0x000000010071e191 libopencv_imgproc.2.4.7.dylib`cv::RemapVec_8u::operator()(cv::Mat const&, void*, short const*, unsigned short const*, void const*, int) const + 263, queue = 'com.apple.root.default-priority, stop reason = EXC_BAD_ACCESS (code=2, address=0x129ab1ecc)
    frame #0: 0x000000010071e191 libopencv_imgproc.2.4.7.dylib`cv::RemapVec_8u::operator()(cv::Mat const&, void*, short const*, unsigned short const*, void const*, int) const + 263
libopencv_imgproc.2.4.7.dylib`cv::RemapVec_8u::operator()(cv::Mat const&, void*, short const*, unsigned short const*, void const*, int) const + 263:
-> 0x10071e191:  vmovd  3(%rcx,%rdi), %xmm3
   0x10071e197:  movzwl 2(%r12,%rbx,2), %edx
   0x10071e19d:  vmovd  (%rcx,%rdi), %xmm4
   0x10071e1a2:  vpunpcklbw %xmm3, %xmm4, %xmm3
  thread #5: tid = 0x743d6, 0x000000010071e191 libopencv_imgproc.2.4.7.dylib`cv::RemapVec_8u::operator()(cv::Mat const&, void*, short const*, unsigned short const*, void const*, int) const + 263, queue = 'com.apple.root.default-priority, stop reason = EXC_BAD_ACCESS (code=2, address=0x129ab1dd6)
    frame #0: 0x000000010071e191 libopencv_imgproc.2.4.7.dylib`cv::RemapVec_8u::operator()(cv::Mat const&, void*, short const*, unsigned short const*, void const*, int) const + 263
libopencv_imgproc.2.4.7.dylib`cv::RemapVec_8u::operator()(cv::Mat const&, void*, short const*, unsigned short const*, void const*, int) const + 263:
-> 0x10071e191:  vmovd  3(%rcx,%rdi), %xmm3
   0x10071e197:  movzwl 2(%r12,%rbx,2), %edx
   0x10071e19d:  vmovd  (%rcx,%rdi), %xmm4
   0x10071e1a2:  vpunpcklbw %xmm3, %xmm4, %xmm3
  thread #7: tid = 0x743d8, 0x000000010071e191 libopencv_imgproc.2.4.7.dylib`cv::RemapVec_8u::operator()(cv::Mat const&, void*, short const*, unsigned short const*, void const*, int) const + 263, queue = 'com.apple.root.default-priority, stop reason = EXC_BAD_ACCESS (code=2, address=0x129ab1ffb)
    frame #0: 0x000000010071e191 libopencv_imgproc.2.4.7.dylib`cv::RemapVec_8u::operator()(cv::Mat const&, void*, short const*, unsigned short const*, void const*, int) const + 263
libopencv_imgproc.2.4.7.dylib`cv::RemapVec_8u::operator()(cv::Mat const&, void*, short const*, unsigned short const*, void const*, int) const + 263:
-> 0x10071e191:  vmovd  3(%rcx,%rdi), %xmm3
   0x10071e197:  movzwl 2(%r12,%rbx,2), %edx
   0x10071e19d:  vmovd  (%rcx,%rdi), %xmm4
   0x10071e1a2:  vpunpcklbw %xmm3, %xmm4, %xmm3
  thread #8: tid = 0x743d9, 0x000000010071e26c libopencv_imgproc.2.4.7.dylib`cv::RemapVec_8u::operator()(cv::Mat const&, void*, short const*, unsigned short const*, void const*, int) const + 482, queue = 'com.apple.root.default-priority, stop reason = EXC_BAD_ACCESS (code=2, address=0x129ab1fb6)
    frame #0: 0x000000010071e26c libopencv_imgproc.2.4.7.dylib`cv::RemapVec_8u::operator()(cv::Mat const&, void*, short const*, unsigned short const*, void const*, int) const + 482
libopencv_imgproc.2.4.7.dylib`cv::RemapVec_8u::operator()(cv::Mat const&, void*, short const*, unsigned short const*, void const*, int) const + 482:
-> 0x10071e26c:  vmovd  3(%rcx,%rax), %xmm3
   0x10071e272:  vmovd  (%rcx,%rax), %xmm4
   0x10071e277:  vpunpcklbw %xmm3, %xmm4, %xmm3
   0x10071e27b:  vpunpcklbw %xmm1, %xmm3, %xmm3
(lldb) bt
* thread #2: tid = 0x743d3, 0x000000010071e191 libopencv_imgproc.2.4.7.dylib`cv::RemapVec_8u::operator()(cv::Mat const&, void*, short const*, unsigned short const*, void const*, int) const + 263, queue = 'com.apple.root.default-priority, stop reason = EXC_BAD_ACCESS (code=2, address=0x129ab1ecc)
    frame #0: 0x000000010071e191 libopencv_imgproc.2.4.7.dylib`cv::RemapVec_8u::operator()(cv::Mat const&, void*, short const*, unsigned short const*, void const*, int) const + 263
    frame #1: 0x00000001007089f0 libopencv_imgproc.2.4.7.dylib`void cv::remapBilinear<cv::FixedPtCast<int, unsigned char, 15>, cv::RemapVec_8u, short>(cv::Mat const&, cv::Mat&, cv::Mat const&, cv::Mat const&, void const*, int, cv::Scalar_<double> const&) + 1828
    frame #2: 0x000000010073254e libopencv_imgproc.2.4.7.dylib`cv::RemapInvoker::operator()(cv::Range const&) const + 2628
    frame #3: 0x0000000100c9b4d4 libopencv_core.2.4.7.dylib`(anonymous namespace)::block_function(void*, unsigned long) + 120
    frame #4: 0x00007fff8fc308f8 libdispatch.dylib`_dispatch_client_callout2 + 8
    frame #5: 0x00007fff8fc30cca libdispatch.dylib`_dispatch_apply_serial + 42
    frame #6: 0x00007fff8fc292ad libdispatch.dylib`_dispatch_client_callout + 8
    frame #7: 0x00007fff8fc303cf libdispatch.dylib`_dispatch_sync_f_invoke + 39
    frame #8: 0x00007fff8fc3062a libdispatch.dylib`dispatch_apply_f + 267
    frame #9: 0x0000000100c9b447 libopencv_core.2.4.7.dylib`cv::parallel_for_(cv::Range const&, cv::ParallelLoopBody const&, double) + 117
    frame #10: 0x0000000100705dc2 libopencv_imgproc.2.4.7.dylib`cv::remap(cv::_InputArray const&, cv::_OutputArray const&, cv::_InputArray const&, cv::_InputArray const&, int, int, cv::Scalar_<double> const&) + 2221
    frame #11: 0x0000000100730153 libopencv_imgproc.2.4.7.dylib`cv::warpPerspectiveInvoker::operator()(cv::Range const&) const + 2341
    frame #12: 0x0000000100c9b4d4 libopencv_core.2.4.7.dylib`(anonymous namespace)::block_function(void*, unsigned long) + 120
    frame #13: 0x00007fff8fc308f8 libdispatch.dylib`_dispatch_client_callout2 + 8
    frame #14: 0x00007fff8fc30849 libdispatch.dylib`_dispatch_apply_invoke + 87
    frame #15: 0x00007fff8fc292ad libdispatch.dylib`_dispatch_client_callout + 8
    frame #16: 0x00007fff8fc2b09e libdispatch.dylib`_dispatch_root_queue_drain + 326
    frame #17: 0x00007fff8fc2c193 libdispatch.dylib`_dispatch_worker_thread2 + 40
    frame #18: 0x00007fff8c8c3ef8 libsystem_pthread.dylib`_pthread_wqthread + 314
    frame #19: 0x00007fff8c8c6fb9 libsystem_pthread.dylib`start_wqthread + 13
(lldb) 

</pre>
```
## History
##### Ilya Lavrenov on 2014-02-11 09:36

```
-   Category changed from calibration, 3d to imgproc, video
```
##### Kirill Kornyakov on 2014-02-17 07:50

```
Matthieu, could you please attach your sample here? Also, can you reproduce the issue with a smaller size image? It would be great to have access to it. May be you could upload it to some hosting?

Also, it would be great if you could debug the issue and send the fix.
-   Description changed from Hi, I'm loading a very large image
    (~600mb), then I use detector+descriptors... to Hi, I'm loading a
    very large image (~600mb), then I use detector+descriptors... More
```
##### Kirill Kornyakov on 2014-02-17 07:54

```
-   Status changed from New to Open
```