0

I am trying to convert the data from an industry camera to a cv::Mat. This is the error I get when backtracing the segmentation fault in gdb.

#0  __memcpy_sse2_unaligned () at ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S:35
#1  0x000000000040cf6f in memcpy (__len=360960, __src=<optimized out>, __dest=<optimized out>)
    at /usr/include/x86_64-linux-gnu/bits/string3.h:51
#2  Camera::getImage (this=this@entry=0x6f59c0, mat=...) at src/Camera.cpp:233
#3  0x000000000040d7e7 in Camera::Camera (this=0x6f59c0, dev=<optimized out>) at src/Camera.cpp:40
#4  0x00000000004327d6 in Utility::initCameras (devMgr=..., left=@0x7fffffffdea0: 0x7ffff53fa4f8, right=@0x7fffffffdea8: 0x809ff8e4)
    at src/utility.cpp:117
#5  0x0000000000407b1e in main (argc=<optimized out>, argv=<optimized out>) at trgt/obstacle.cpp:150

So I can clearly say that there is any problem with the command to memcpy:

std::memcpy(mat.ptr(),static_cast<char*>(mRequest->imageData.read()), mRequest->imageSize.read());

Now I don't really understand why the error is occuring. In another version of the program I am using it is working, but the images look very bad.

Maybe one of you has an idea what a possible error source could be.

hGen
  • 2,235
  • 6
  • 23
  • 43
  • My guess would be that `mat` is too small to fit the source. – kirbyfan64sos Aug 12 '15 at 14:05
  • Also, what is the type of `imageSize`? – kirbyfan64sos Aug 12 '15 at 14:06
  • did you initialize mat correctly? what does it read for its width and height? what does `mRequest->imageSize.read()` return for it's size? – RyanP Aug 12 '15 at 14:11
  • `mRequest->imageSIze.read()` simply returns the lenght of the source as an integer, which should actually be the right type considering that I access mat.ptr(). The initialized Mat it just an empty Matrix I pass into the function as a reference. – hGen Aug 12 '15 at 14:16
  • please dont copy to a mat object but just create a new one: `cv::Mat matUsingDataFromSomewhereElse = cv::Mat(height, width, type, static_cast(mRequest->imageData.read()))` – Micka Aug 12 '15 at 14:46
  • I tried that but itkind of killed my program and the requests given by the camera. The copying procesess takes too long for the request to be valid. – hGen Aug 12 '15 at 14:47
  • that constructor doesnt copy anything... it just creates a matrix header and links it to the provided data address... – Micka Aug 12 '15 at 14:50
  • Well the problem is that this method it not working for more than 1 frame. after the first one the image acquisition just fails because of invalid requests – hGen Aug 12 '15 at 15:10
  • if you use the exactly same code without Mat at all, more than one image is captured? did you try to malloc some memory and copy your image to that memory? can you post minimal code samples with / without cv::Mat that don't work / do work? – Micka Aug 13 '15 at 06:10

0 Answers0