ByteBuffer to byte [] on AsyncTask result for fatal signal 11 (SIGSEGV)
I am using an image processing application. To get started, I get an image that I pass to the AsyncTask:
@Override
public void onImageAvailable(ImageReader reader) {
int jump = 5; //Le nombre d'image à sauter avant d'en traiter une, pour liberer de la mémoire
Image readImage = reader.acquireNextImage();
ImageCopy tmpImage = new ImageCopy(readImage.getPlanes()[0].getBuffer(),readImage.getWidth(),readImage.getHeight());
readImage.close();
if(count == jump){
//Image Process here
new ImageProcess().execute(tmpImage);
count = 0;
realCount++;
}
else count++;
totalCount++;
}
ImageCopy is a class that I created because the image class is causing problems with AsyncTask. Then this is what the ImageProcess class has:
@Override
protected IplImage doInBackground(ImageCopy... images) {
ByteBuffer buffer = images[0].getBuffer();
int width = images[0].getWidth();
int height = images[0].getHeight();
//Conversion de l'Image passé en paramêtre en une IplImage
IplImage iplImage = bufferToIpl(buffer,width,height);
//Egalisation de l'histogramme en niveau de gris
opencv_imgproc.cvEqualizeHist(iplImage,iplImage);
//Seuillage de l'image
opencv_imgproc.cvThreshold(iplImage,iplImage,96.0,255.0,opencv_imgproc.CV_THRESH_BINARY);
//TEST : Enregistrement image
//opencv_highgui.cvSaveImage("test.jpg",iplImage);
return iplImage;
}
But the problem comes from the bufferToIple method:
protected IplImage bufferToIpl(ByteBuffer buffer, int width, int height) {
int f = 1;// SUBSAMPLING_FACTOR;
//Conversion du ByteBuffer en un byte array
byte[] data = new byte[buffer.remaining()];
buffer.get(data);
// First, downsample our image and convert it into a grayscale IplImage
IplImage grayImage = IplImage.create(width / f, height / f, opencv_core.IPL_DEPTH_8U, 1);
int imageWidth = grayImage.width();
int imageHeight = grayImage.height();
int dataStride = f * width;
int imageStride = grayImage.widthStep();
ByteBuffer imageBuffer = grayImage.getByteBuffer();
for (int y = 0; y < imageHeight; y++) {
int dataLine = y * dataStride;
int imageLine = y * imageStride;
for (int x = 0; x < imageWidth; x++) {
imageBuffer.put(imageLine + x, data[dataLine + f * x]);
}
}
return grayImage;
}
Most accurately of these lines:
byte[] data = new byte[buffer.remaining()];
buffer.get(data);
When I add buffer.get (data) to my code, I have these runtime errors:
- 06-20 15: 25: 05.524 4015-4028 / ca.uqtr.camera2videobasic W / art: Suspending all streams takes: 5.253 m.
- 06-20 15: 25: 10.020 4015-4100 / ca.uqtr.camera2videobasic A / libc: fatal signal 11 (SIGSEGV), code 1, error addr 0xe1a3c000 in tid 4100 (AsyncTask # 1)
It seems that it came from AsyncTask and I have no idea why ...
+3
Widea
source
to share
No one has answered this question yet
Check out similar questions:
311
67
ten
3
1
1
0
0
0
0