0

Hey guys I have an issue with my opencv 2.3.0

All I am trying to do is extract SIFT features from an image I have downloaded. Now the image is very large (around 120MB) 6124w X 7636h PNG

and the error I see is:

OpenCV Error: Insufficient memory (Failed to allocate 748205824 bytes) in OutOfMemoryError, file /home/ros/Desktop/OpenCV-2.3.0/modules/core/src/alloc.cpp, line 52
terminate called after throwing an instance of 'cv::Exception'
what():  /home/ros/Desktop/OpenCV-2.3.0/modules/core/src/alloc.cpp:52: error: (-4)    Failed to allocate 748205824 bytes in function OutOfMemoryError

Now I know that the error occures when this line is called .

cv::FeatureDetector * siftfeaturedetector = new cv::SiftFeatureDetector( siftLevel_, 10.0, 4,3,-1,0 );
siftfeaturedetector->detect(imgMat, keypts); // HERE

So I am wondering(because I have read some solutions saying to compile with 64bit) how to solve this using a 32 bit linux VM. Also a side note I have 4 GB of memory so the 750MB shouldn't be a problem.

ALSO if you know why its taking 750MBs and not something closer to 120MB I would love to know why that is the case as well :)

Jay
  • 2,656
  • 1
  • 16
  • 24
  • 1
    `748205824 / 6124 / 7636 = 16`, so perhaps it is using 4 floats per pixel rather than 4 chars. You may have 4gb total memory, but that doesn't mean your program will have access to all of it, and it may be fragmented so that there is not enough contiguous space to meet the request. – Retired Ninja May 29 '14 at 03:05
  • 1
    From what I understand about Sift, it has to calculate features based on every pixel for every pixel in the picture. You could try using the size or making it greyscale to reduce the memory you need. You can use `cv::resize` or `cvLoadImage("image.jpg",CV_LOAD_IMAGE_GRAYSCALE);` to do this. – Fantastic Mr Fox May 29 '14 at 04:45
  • 1
    Assuming the program legitimately needs to perform 750MB allocations, you're generally going to have a hard time reliably satisfying that in a 32-bit virtual address space. – nobody May 29 '14 at 05:04
  • Can you show us how you are loading and what operations you are doing to the image? Maybe you could also provide a link to the image and code and we can try it ourselves? – Fantastic Mr Fox May 29 '14 at 05:12
  • @Ben its just a simple `imread` as a `cv::Mat` And its a USGS image taken from a JP2 image and `gdal_translated` to a PNG – Jay May 29 '14 at 17:59
  • Just a note, I've hit this using opencv with python on a Raspberry Pi 2. The 'interesting' thing is that I have very small greyscale images and the call for memory is smaller but fails, even given [I hope!] enough memory: `kp1, des1 = sift.detectAndCompute(img1,None) cv2.error: /home/pi/opencv-2.4.10/modules/core/src/alloc.cpp:52: error: (-4) Failed to allocate 78643204 bytes in function OutOfMemoryError` – Hugh Barnard May 22 '15 at 13:42

0 Answers0