0
我正在嘗試用android renderscript編寫應用程序,未能寫入函數的邊緣檢測部分。如果設備的android版本小於或等於Lolipop,但在其他設備中,它大部分時間(根據我觀察到的不同而不依賴於代碼更改而從構建到構建而變化)給出了SIGSEV 11或SIGBUS 7錯誤地址錯誤。Android Renderscript地址錯誤
這是邊緣檢測RS實現:
uchar4 __attribute__((kernel)) Edge2(uchar in,uint32_t x, uint32_t y) {
//sobel
uint32_t n = max(y - 1, (uint32_t)0);
uint32_t s = min(y + 1, (uint32_t)height);
uint32_t e = min(x + 1, (uint32_t)width);
uint32_t w = max(x - 1, (uint32_t)0);
const uchar *e11 = rsGetElementAt(gIn, w, n);
const uchar *e21 = rsGetElementAt(gIn, x, n);
const uchar *e31 = rsGetElementAt(gIn, e, n);
const uchar *e12 = rsGetElementAt(gIn, w, y);
const uchar *e22 = rsGetElementAt(gIn, x, y);
const uchar *e32 = rsGetElementAt(gIn, e, y);
const uchar *e13 = rsGetElementAt(gIn, w, s);
const uchar *e23 = rsGetElementAt(gIn, x, s);
const uchar *e33 = rsGetElementAt(gIn, e, s);
float r1 = ((*e12 - *e32)*3 + *e11 + *e13 - *e31 - *e33);
float r2 = ((*e21 - *e23)*3 + *e11 - *e13 + *e31 - *e33);
uchar res=(uchar)clamp(sqrt((r1*r1+r2*r2)), 0.0f, 255.0f);
return (uchar4){res, res, res,(uchar)255};
}
或這不工作過:
void Edge(const uchar *v_in, uchar4 *v_out, const void *usrData, uint32_t x, uint32_t y){
uint32_t n = max(y - 1, (uint32_t)0);
uint32_t s = min(y + 1, (uint32_t)height);
uint32_t e = min(x + 1, (uint32_t)width);
uint32_t w = max(x - 1, (uint32_t)0);
const uchar *e11 = rsGetElementAt(gIn, w, n);
const uchar *e21 = rsGetElementAt(gIn, x, n);
const uchar *e31 = rsGetElementAt(gIn, e, n);
const uchar *e12 = rsGetElementAt(gIn, w, y);
const uchar *e22 = rsGetElementAt(gIn, x, y);
const uchar *e32 = rsGetElementAt(gIn, e, y);
const uchar *e13 = rsGetElementAt(gIn, w, s);
const uchar *e23 = rsGetElementAt(gIn, x, s);
const uchar *e33 = rsGetElementAt(gIn, e, s);
// 1 0 -1
// 2 0 -2
// 1 0 -1
float r1 = ((*e12 - *e32)*3 + *e11 + *e13 - *e31 - *e33);
float r2 = ((*e21 - *e23)*3 + *e11 - *e13 + *e31 - *e33);
uchar res=(uchar)clamp(sqrt((r1*r1+r2*r2)), 0.0f, 255.0f);
*v_out = (uchar4){res, res, res,(uchar)255};
}
最後兩行(返回和UCHAR部分)給出了錯誤。順便說一句,如果我拒絕「返回10」或類似的東西,它的作品。
這是java的部分:
public Bitmap doFilter(byte[] data) {
_inData.copy1DRangeFrom(0, _previewSamples, data);
_inData_yuv.copyFrom(data);
_filtersLib.forEach_Edge2(_inData, _outData);
yuvToRgbIntrinsic.forEach(_outData_rgb);
_filtersLib.forEach_combine(_outData, _outData);
_outData.copyTo(_outBmp);
return _outBmp;//Bitmap.createScaledBitmap(_outBmp, x, y, false);
}
有在應用中的多個scriptC實例。這是一個問題還是可以? (在其它RS文件工作沒有任何問題完全相同的Sobel邊緣檢測碼)
錯誤:
Fatal signal 7 (SIGBUS), code 2, fault addr 0x8cf7ffff in tid 22666 (om.sketchcamera)
[ 12-27 18:36:37.275 317: 317 W/ ]
debuggerd: handling request: pid=22625 uid=10124 gid=10124 tid=22666
裝置:一般移動機器人一個(機器人N)
感謝您的幫助
只需檢查您是否使用Renderscript支持庫。 –
都嘗試過,他們都給出了相同的錯誤 –