0

Quelqu'un peut-il me fournir quelques directives sur la façon dont je peux porter ce code à renderscript pour de meilleures performances.Comment déplacer ce code de java à Renderscript?

private void someMethod() { 
for (int i = 0; i < src.rows(); i++) { 
    for (int j = 0; j < src.cols(); j++) { 
    double hsv[] = src.get(i, j); 
    double modifedHSV[] = this.modifyHSV(new Scalar(hsv), selectedRepaintColor, mean); 
    res.put(i, j, modifedHSV); 
    } 
} 
} 
private double[] modifyHSV(Scalar hsvImage, Scalar selectedHsv, Scalar mean) { 

Double h_final = hsvImage.val[0] - mean.val[0] + selectedHsv.val[0]; 
Double s_final = hsvImage.val[1] - mean.val[1] + selectedHsv.val[1]; 
Double v_final = hsvImage.val[2] - mean.val[2] + selectedHsv.val[2]; 

h_final = (h_final <= 0) ? h_final + 180 : h_final; 
s_final = (s_final <= 0) ? 0 : s_final; 
v_final = (v_final <= 0) ? 0 : v_final; 

double[] final_hsv = new double[3]; 
final_hsv[0] = h_final; 
final_hsv[1] = s_final; 
final_hsv[2] = v_final; 
return final_hsv; 
} 
+0

Vous aurez au port cette RS avec le approprié ' Attribuez des objets et définissez votre propre noyau. Si vous êtes nouveau sur RS, vous pouvez trouver une discussion comme [this] (https://youtu.be/3ynA92x8WQo) utile. –

Répondre

0

Vous pouvez essayer quelque chose comme ceci:

hsv.rs:

#pragma rs_fp_relaxed 
float3 mean; 
float3 selectedHsv; 
float3 RS_KERNEL process_hsv(float3 input) { 
    float3 hsv_final = input - mean + selectedHsv; 

    hsv_final.x = (hsv_final.x <= 0.f) ? hsv_final.x + 180.f : hsv_final.x; 
    hsv_final.y = (hsv_final.y <= 0.f) ? 0.f : hsv_final.y; 
    hsv_final.z = (hsv_final.z <= 0.f) ? 0.f : hsv_final.z; 

    return hsv_final; 
} 

java:

ScriptC_hsv script; 
void init() { 
    script = new ScriptC_hsv(rs); 
} 
float[] process_hsv(float[] input_array, Float3 selectedHsv, Float3 mean) { 
    script.set_mean(mean); 
    script.set_selectedHsv(selectedHsv); 
    output_array = new float[size]; 
    Type t = Type.createXY(rs, Element.F32_3(rs), columns, rows); 
    Allocation input = Allocation.createTyped(rs, t, size, Allocation.USAGE_SCRIPT); 
    Allocation output = Allocation.createTyped(rs, t, size, Allocation.USAGE_SCRIPT); 
    input.copyFrom(input_array); 
    script.forEach_process_hsv(input, output); 
    output.copyTo(output_array); 
    return output_array; 
} 
+0

merci beaucoup, @sakridge. Je vais mettre en œuvre ceci et vous faire savoir: D –