다음 코드를 최적화하는 데 조언이 필요합니까? 코드는 먼저 이미지를 그레이 스케일하고 반전 한 다음 임계 값을 지정합니다 (포함되지 않은 코드는 사소한 것입니다). 그런 다음 각 행과 열의 요소를 합합니다 (모든 요소는 1 또는 0입니다). 그런 다음 가장 높은 값을 갖는 행 및 열의 행 및 열 색인을 찾습니다.행과 열 셀의 렌더 스크립트 합계 최적화
이 코드는 이미지의 중심을 찾기 위해 생각하고 그것을 작동,하지만 난 내가 그렇게 감소 커널을 사용할 수 없습니다, API 23 개발하고 있어요
더 빨리 만들고 싶어한다.
자바 스 니펫 :
private int[] sumValueY = new int[640];
private int[] sumValueX = new int[480];
rows_indices_alloc = Allocation.createSized(rs, Element.I32(rs), height, Allocation.USAGE_SCRIPT);
col_indices_alloc = Allocation.createSized(rs, Element.I32(rs), width, Allocation.USAGE_SCRIPT);
public RenderscriptProcessor(RenderScript rs, int width, int height)
{
mScript.set_gIn(mIntermAllocation);
mScript.forEach_detectX(rows_indices_alloc);
mScript.forEach_detectY(col_indices_alloc);
rows_indices_alloc.copyTo(sumValueX);
col_indices_alloc.copyTo(sumValueY);
}
Renderscript.rs 스 니펫 :
#pragma version(1)
#pragma rs java_package_name(org.gearvrf.renderscript)
#include "rs_debug.rsh"
#pragma rs_fp_relaxed
const int mImageWidth=640;
const int mImageHeight=480;
int32_t maxsX=-1;
int32_t maxIndexX;
int32_t maxsY=-1;
int32_t maxIndexY;
rs_allocation gIn;
void detectX(int32_t v_in, int32_t x, int32_t y) {
int32_t sum=0;
for (int i = 0; i < (mImageWidth); i++) {
float4 f4 = rsUnpackColor8888(rsGetElementAt_uchar4(gIn, i, x));
sum+=(int)f4.r;
}
if((sum>maxsX)){
maxsX=sum;
maxIndexX = x;
}
}
void detectY(int32_t v_in, int32_t x, int32_t y) {
int32_t sum=0;
for (int i = 0; i < (mImageHeight); i++) {
float4 f4 = rsUnpackColor8888(rsGetElementAt_uchar4(gIn, x, i));
sum+=(int)f4.r;
}
if((sum>maxsY)){
maxsY=sum;
maxIndexY = x;
}
}
어떤 도움을 다시 int로 당시
이 떠 INT에서 변환