Skip to content

Instantly share code, notes, and snippets.

@brannondorsey
Created June 5, 2013 01:46
Show Gist options
  • Save brannondorsey/5711072 to your computer and use it in GitHub Desktop.
Save brannondorsey/5711072 to your computer and use it in GitHub Desktop.
Trying to figure out why this isn't noticing the differences between the current frame and the previous. It seems like the assignment on line 36 isn't doing its job properly.
void testApp::setSequences(){
int pixelThreshold = 20; //percent similarity each individual pixel needs to pass
int imgPercentNeededToPass = 80; //percent of pixels that must pass threshold test
int checkEveryIncrement = 10; //number of pixels before next pixel comparison
int maxPixDiffToPass = (pixelThreshold*255)/100; //converts percent to a max pixel change value
vector<long> cutFrames;
myVideo.setFrame(1);
ofPixelsRef prevPixelsRef = myVideo.getPixelsRef();
for(int i = 2; i<myVideo.getTotalNumFrames(); i++){
int numThatPass = 0; //holds number of pixels that pass
myVideo.setFrame(i); // start at first frame
myVideo.draw(0,0);
//cout<<"is the frame new: "<<ofToString(myVideo.isFrameNew())<<endl;
ofPixelsRef pixelsRef = myVideo.getPixelsRef();
//loop through each pixel in the image
for(int j = 0; j < myVideo.getWidth(); j += checkEveryIncrement){
for(int k = 0; k < myVideo.getHeight(); k += checkEveryIncrement){
float prevLightness = prevPixelsRef.getColor(j,k).getLightness();
float lightness = pixelsRef.getColor(j,k).getLightness();
//cout<<"the lightness is "<<lightness<<" and the previous lightness is "<<prevLightness<<endl;
if(abs(prevLightness-lightness) <= maxPixDiffToPass){
numThatPass++;
}
if(prevLightness != lightness) cout<<"there is a differance"<<endl;
}
}
//cout<<"the first pixel of frame "<<ofToString(i)<<" is "<<ofToString(pixelsRef.getColor(1,1).getLightness())<<endl;
if(numThatPass/myVideo.getWidth()*myVideo.getHeight() >= imgPercentNeededToPass/100){
//if enough pixels passed
cutFrames.push_back(i);
//cout<<"found a cut!"<<endl;
}
prevPixelsRef = pixelsRef;
}//go to next frame
cout<<"there are "+ofToString(cutFrames.size())<<" cuts in this movie"<<endl;
}
@brannondorsey
Copy link
Author

Basically its registering both pixelsRef and prevPixelsRef as a reference to the same thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment