Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

I made harmonic mean code for two images. But

$
0
0

@bemoregt wrote:

Hi, All.

I made harmonic mean code for two images.

// Function that returns harmonic mean.
int harmonicMean(float arr[], int n)
{
// Declare sum variables and initialize
// with zero.
float sum = 0;
for (int i = 0; i < n; i++)
sum = sum + 1 / arr[i];

return (int)n/sum;

}

//--------------------------------------------------------------
void ofApp::setup(){

aa.load("/Users/kerbal/Desktop/low.png");
bb.load("/Users/kerbal/Desktop/high.png");

ofPixels p1 = aa.getPixels();
ofPixels p2 = bb.getPixels();
ofPixels pp = aa.getPixels();

float arr[] = {};
for(int i = 0; i < aa.getWidth()*aa.getHeight(); i++){
    arr[0]= p1[i];
    arr[1]= p2[i];
    
    pp[i]= harmonicMean(arr, 2); // <-bad access error happen
}
cc.setFromPixels(pp);
cc.update();

}

But bad access error happen like above.
What’s wrong to me ?

Thanks.
Best,
@bemoregt.

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4929