- now fixed....
- float checkMovement(int x, int y, int w, int h)
- {
- int movementSum = 0; // Amount of movement in the frame
- for(int ypos = y;ypos < y + h; ypos ++)
- {
- for(int xpos = x;xpos < x + w; xpos ++)
- {
- int index = xpos + (ypos * video.width);
- color currColor = video.pixels[index];
- color prevColor = previousFrame[index];
- int currR = (currColor >> 16) & 0xFF; // Like red(), but faster
- int currG = (currColor >> 8) & 0xFF;
- int currB = currColor & 0xFF;
- // Extract red, green, and blue components from previous pixel
- int prevR = (prevColor >> 16) & 0xFF;
- int prevG = (prevColor >> 8) & 0xFF;
- int prevB = prevColor & 0xFF;
- // Compute the difference of the red, green, and blue values
- int diffR = abs(currR - prevR);
- int diffG = abs(currG - prevG);
- int diffB = abs(currB - prevB);
- //
- movementSum += diffR + diffG + diffB;
- // Render the difference image to the screen
- pixels[index] = color(diffR, diffG, diffB);
- // The following line is much faster, but more confusing to read
- //pixels[i] = 0xff000000 | (diffR << 16) | (diffG << 8) | diffB;
- // Save the current color into the 'previous' buffer
- // keep the current pixel colour for comparison next time
- previousFrame[index] = currColor;
- }
- }
- int totalPossibleMovement = w*h*255*3; // width * height (of area of interest) * 255 (is the max difference per colour) * 3 (number of colour channels eg:rgb)
- float percentage = (float)movementSum / (float)totalPossibleMovement;
- percentage = percentage * 100.0f;
- return percentage;
- }
↧
Re : Issues with TargetRegion in frame differencing
↧