# OutofMemoryError when using large image in StructuredEdgeDetection

**URL:** <https://forum.opencv.org/t/outofmemoryerror-when-using-large-image-in-structurededgedetection/2530>\
**Category:** Android/Java\
**Tags:** ximgproc\
**Created:** [April 1, 2021, 9:08am UTC](https://forum.opencv.org/t/outofmemoryerror-when-using-large-image-in-structurededgedetection/2530 "2021-04-01T09:08:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![satheesh\_kumar](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/satheesh_kumar/32/1659_2.png) [@satheesh\_kumar](https://forum.opencv.org/u/satheesh_kumar)\
**Post date:** [April 1, 2021, 9:08am UTC](https://forum.opencv.org/t/outofmemoryerror-when-using-large-image-in-structurededgedetection/2530/1 "2021-04-01T09:08:39Z")

</div>

I’m trying to use the detectEdges function from org.opencv.ximgproc.StructuredEdgeDetection class .

This is the sample code I’m using  
StructuredEdgeDetection pDollar = createStructuredEdgeDetection(file.toString());  
pDollar.detectEdges(mat, edges);

The above code is working fine if the size of the image is small. When I tried with a large resolution image (12 MP). I’m getting OutOfMemoryError. Is there any solution to manage this issue ?

---

<div class="post-metadata">

**Author:** ![matti.vuori](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@matti.vuori](https://forum.opencv.org/u/matti.vuori)\
**Post date:** [April 1, 2021, 10:59am UTC](https://forum.opencv.org/t/outofmemoryerror-when-using-large-image-in-structurededgedetection/2530/2 "2021-04-01T10:59:09Z")

</div>

Assuming everything in your code is correct, and that you don’t need absolute precision, you could resize the image smaller, do the detection, and then scale the results back to match the original size
